Changeset 8d66610 for libcfa/src/concurrency/alarm.cfa
- Timestamp:
- May 21, 2021, 4:48:10 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- f1bce515
- Parents:
- 5407cdc (diff), 7404cdc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
libcfa/src/concurrency/alarm.cfa (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/alarm.cfa
r5407cdc r8d66610 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; 57 this.timeval = __kernel_get_time() + alarm; 52 58 set = false; 53 59 type = User; 54 60 } 55 61 56 void ?{}( alarm_node_t & this, processor * proc, Time alarm, Duration period ) with( this ) { 62 void ?{}( alarm_node_t & this, processor * proc, Duration alarm, Duration period ) with( this ) { 63 this.initial = alarm; 64 this.period = period; 57 65 this.proc = proc; 58 this.alarm = alarm; 59 this.period = period; 66 this.timeval = __kernel_get_time() + alarm; 60 67 set = false; 61 68 type = Kernel; 62 69 } 63 void ?{}( alarm_node_t & this, Alarm_Callback callback, Time alarm, Duration period ) with( this ) { 64 this.alarm = alarm; 65 this.period = period; 70 void ?{}( alarm_node_t & this, Alarm_Callback callback, Duration alarm, Duration period ) with( this ) { 66 71 this.callback = callback; 72 this.initial = alarm; 73 this.period = period; 74 this.timeval = __kernel_get_time() + alarm; 67 75 set = false; 68 76 type = Callback; … … 77 85 void insert( alarm_list_t * this, alarm_node_t * n ) { 78 86 alarm_node_t * it = & (*this)`first; 79 while( it && (n-> alarm > it->alarm) ) {87 while( it && (n->timeval > it->timeval) ) { 80 88 it = & (*it)`next; 81 89 } … … 105 113 lock( event_kernel->lock __cfaabi_dbg_ctx2 ); 106 114 { 107 verify( validate( alarms ) ); 108 bool first = ! & alarms`first; 115 /* paranoid */ verify( validate( alarms ) ); 109 116 110 __cfadbg_print_safe( preemption, " KERNEL: alarm inserting %p (%lu).\n", this, this->alarm.tn ); 117 Time curr = __kernel_get_time(); 118 __cfadbg_print_safe( preemption, " KERNEL: alarm inserting %p (%lu -> %lu).\n", this, curr.tn, this->timeval.tn ); 111 119 insert( &alarms, this ); 112 if( first ) { 113 __kernel_set_timer( alarms`first.alarm - __kernel_get_time() ); 114 } 120 __kernel_set_timer( this->timeval - curr); 121 this->set = true; 115 122 } 116 123 unlock( event_kernel->lock ); 117 this->set = true;118 124 enable_interrupts(); 119 125 } … … 124 130 { 125 131 verify( validate( event_kernel->alarms ) ); 126 remove( *this ); 132 if (this->set) remove( *this ); 133 this->set = false; 127 134 } 128 135 unlock( event_kernel->lock ); 129 136 enable_interrupts(); 130 this->set = false;131 137 } 132 138 … … 136 142 137 143 void sleep( Duration duration ) { 138 alarm_node_t node = { active_thread(), __kernel_get_time() +duration, 0`s };144 alarm_node_t node = { active_thread(), duration, 0`s }; 139 145 140 146 register_self( &node );
Note:
See TracChangeset
for help on using the changeset viewer.