Changeset c457dc41 for libcfa/src/concurrency/alarm.cfa
- Timestamp:
- May 14, 2021, 5:23:49 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 353aaba
- Parents:
- e2f601f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/alarm.cfa
re2f601f rc457dc41 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 ); 115 120 } 116 121 unlock( event_kernel->lock ); … … 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.