- File:
-
- 1 edited
-
libcfa/src/concurrency/alarm.cfa (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/alarm.cfa
rafd7faf ra3821fa 38 38 39 39 void __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 ); 47 42 } 48 43 … … 51 46 //============================================================================================= 52 47 53 void ?{}( alarm_node_t & this, $thread * thrd, Duration alarm, Duration period) with( this ) { 54 this.initial = alarm; 55 this.period = period; 48 void ?{}( alarm_node_t & this, $thread * thrd, Time alarm, Duration period) with( this ) { 56 49 this.thrd = thrd; 50 this.alarm = alarm; 51 this.period = period; 57 52 set = false; 58 53 type = User; 59 54 } 60 55 61 void ?{}( alarm_node_t & this, processor * proc, Duration alarm, Duration period ) with( this ) { 62 this.initial = alarm; 63 this.period = period; 56 void ?{}( alarm_node_t & this, processor * proc, Time alarm, Duration period ) with( this ) { 64 57 this.proc = proc; 58 this.alarm = alarm; 59 this.period = period; 65 60 set = false; 66 61 type = Kernel; 67 62 } 68 void ?{}( alarm_node_t & this, Alarm_Callback callback, Durationalarm, Duration period ) with( this ) {69 this. initial= alarm;70 this.period = period;63 void ?{}( alarm_node_t & this, Alarm_Callback callback, Time alarm, Duration period ) with( this ) { 64 this.alarm = alarm; 65 this.period = period; 71 66 this.callback = callback; 72 67 set = false; … … 82 77 void insert( alarm_list_t * this, alarm_node_t * n ) { 83 78 alarm_node_t * it = & (*this)`first; 84 while( it && (n-> timeval > it->timeval) ) {79 while( it && (n->alarm > it->alarm) ) { 85 80 it = & (*it)`next; 86 81 } … … 110 105 lock( event_kernel->lock __cfaabi_dbg_ctx2 ); 111 106 { 112 Time curr = __kernel_get_time();113 this->timeval = curr + this->initial;107 verify( validate( alarms ) ); 108 bool first = ! & alarms`first; 114 109 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 ); 118 111 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 } 121 115 } 122 116 unlock( event_kernel->lock ); 117 this->set = true; 123 118 enable_interrupts(); 124 119 } … … 129 124 { 130 125 verify( validate( event_kernel->alarms ) ); 131 if (this->set) remove( *this ); 132 this->set = false; 126 remove( *this ); 133 127 } 134 128 unlock( event_kernel->lock ); 135 129 enable_interrupts(); 130 this->set = false; 136 131 } 137 132 … … 141 136 142 137 void 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 }; 144 139 145 140 register_self( &node );
Note:
See TracChangeset
for help on using the changeset viewer.