Ignore:
File:
1 edited

Legend:

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

    rafd7faf ra3821fa  
    3838
    3939void __kernel_set_timer( Duration alarm ) {
    40         alarm = max(alarm, 1`us);
    41         itimerval otv @= { 0 };
    42         getitimer( ITIMER_REAL, &otv );
    43         Duration od = { otv.it_value };
    44         if(od == 0 || od > alarm) {
    45                 setitimer( ITIMER_REAL, &(itimerval){ alarm }, 0p );
    46         }
     40        verifyf(alarm >= 1`us || alarm == 0, "Setting timer to < 1us (%jins)", alarm`ns);
     41        setitimer( ITIMER_REAL, &(itimerval){ alarm }, 0p );
    4742}
    4843
     
    5146//=============================================================================================
    5247
    53 void ?{}( alarm_node_t & this, $thread * thrd, Duration alarm, Duration period) with( this ) {
    54         this.initial = alarm;
    55         this.period  = period;
     48void ?{}( alarm_node_t & this, $thread * thrd, Time alarm, Duration period) with( this ) {
    5649        this.thrd = thrd;
     50        this.alarm = alarm;
     51        this.period = period;
    5752        set = false;
    5853        type = User;
    5954}
    6055
    61 void ?{}( alarm_node_t & this, processor * proc, Duration alarm, Duration period ) with( this ) {
    62         this.initial = alarm;
    63         this.period  = period;
     56void ?{}( alarm_node_t & this, processor * proc, Time alarm, Duration period ) with( this ) {
    6457        this.proc = proc;
     58        this.alarm = alarm;
     59        this.period = period;
    6560        set = false;
    6661        type = Kernel;
    6762}
    68 void ?{}( alarm_node_t & this, Alarm_Callback callback, Duration alarm, Duration period ) with( this ) {
    69         this.initial = alarm;
    70         this.period  = period;
     63void ?{}( alarm_node_t & this, Alarm_Callback callback, Time alarm, Duration period ) with( this ) {
     64        this.alarm = alarm;
     65        this.period = period;
    7166        this.callback = callback;
    7267        set = false;
     
    8277void insert( alarm_list_t * this, alarm_node_t * n ) {
    8378        alarm_node_t * it = & (*this)`first;
    84         while( it && (n->timeval > it->timeval) ) {
     79        while( it && (n->alarm > it->alarm) ) {
    8580                it = & (*it)`next;
    8681        }
     
    110105        lock( event_kernel->lock __cfaabi_dbg_ctx2 );
    111106        {
    112                 Time curr = __kernel_get_time();
    113                 this->timeval = curr + this->initial;
     107                verify( validate( alarms ) );
     108                bool first = ! & alarms`first;
    114109
    115                 /* paranoid */ verify( validate( alarms ) );
    116 
    117                 __cfadbg_print_safe( preemption, " KERNEL: alarm inserting %p (%lu -> %lu).\n", this, curr.tn, this->timeval.tn );
     110                __cfadbg_print_safe( preemption, " KERNEL: alarm inserting %p (%lu).\n", this, this->alarm.tn );
    118111                insert( &alarms, this );
    119                 __kernel_set_timer( this->initial );
    120                 this->set = true;
     112                if( first ) {
     113                        __kernel_set_timer( alarms`first.alarm - __kernel_get_time() );
     114                }
    121115        }
    122116        unlock( event_kernel->lock );
     117        this->set = true;
    123118        enable_interrupts();
    124119}
     
    129124        {
    130125                verify( validate( event_kernel->alarms ) );
    131                 if (this->set) remove( *this );
    132                 this->set = false;
     126                remove( *this );
    133127        }
    134128        unlock( event_kernel->lock );
    135129        enable_interrupts();
     130        this->set = false;
    136131}
    137132
     
    141136
    142137void sleep( Duration duration ) {
    143         alarm_node_t node = { active_thread(), duration, 0`s };
     138        alarm_node_t node = { active_thread(), __kernel_get_time() + duration, 0`s };
    144139
    145140        register_self( &node );
Note: See TracChangeset for help on using the changeset viewer.