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