Ignore:
Timestamp:
Jun 8, 2017, 1:48:12 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
a724ac1
Parents:
8b8152e
Message:

First implementation of preemption, does not appear to work with scheduling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/alarm.c

    r8b8152e r82ff5845  
    1616
    1717extern "C" {
     18#include <errno.h>
     19#include <stdio.h>
     20#include <string.h>
    1821#include <time.h>
     22#include <unistd.h>
    1923#include <sys/time.h>
    2024}
     
    2226#include "alarm.h"
    2327#include "kernel_private.h"
     28#include "libhdr.h"
    2429#include "preemption.h"
    2530
     
    3136        timespec curr;
    3237        clock_gettime( CLOCK_REALTIME, &curr );
    33         return ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
     38        __cfa_time_t curr_time = ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
     39        LIB_DEBUG_DO(
     40                char text[256];
     41                __attribute__((unused)) int len = snprintf( text, 256, "Kernel : current time is %lu\n", curr_time );
     42                LIB_DEBUG_WRITE( STDERR_FILENO, text, len );
     43        );
     44        return curr_time;
    3445}
    3546
    3647void __kernel_set_timer( __cfa_time_t alarm ) {
     48
     49        LIB_DEBUG_DO(
     50                char text[256];
     51                __attribute__((unused)) int len = snprintf( text, 256, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm );
     52                LIB_DEBUG_WRITE( STDERR_FILENO, text, len );
     53        );
     54
    3755        itimerval val;
    3856        val.it_value.tv_sec = alarm / TIMEGRAN;                 // seconds
     
    128146        lock( &systemProcessor->alarm_lock );
    129147        {
     148                bool first = !systemProcessor->alarms.head;
     149
    130150                insert( &systemProcessor->alarms, this );
    131151                if( systemProcessor->pending_alarm ) {
    132152                        tick_preemption();
     153                }
     154                if( first ) {
     155                        __kernel_set_timer( systemProcessor->alarms.head->alarm - __kernel_get_time() );
    133156                }
    134157        }
Note: See TracChangeset for help on using the changeset viewer.