Changes in src/libcfa/concurrency/alarm.c [1c273d0:4aa2fb2]
- File:
-
- 1 edited
-
src/libcfa/concurrency/alarm.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/alarm.c
r1c273d0 r4aa2fb2 16 16 17 17 extern "C" { 18 #include <errno.h>19 #include <stdio.h>20 #include <string.h>21 18 #include <time.h> 22 #include <unistd.h>23 19 #include <sys/time.h> 24 20 } … … 26 22 #include "alarm.h" 27 23 #include "kernel_private.h" 28 #include "libhdr.h"29 24 #include "preemption.h" 30 25 … … 36 31 timespec curr; 37 32 clock_gettime( CLOCK_REALTIME, &curr ); 38 __cfa_time_t curr_time = ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec; 39 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time ); 40 return curr_time; 33 return ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec; 41 34 } 42 35 43 36 void __kernel_set_timer( __cfa_time_t alarm ) { 44 LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm );45 37 itimerval val; 46 38 val.it_value.tv_sec = alarm / TIMEGRAN; // seconds … … 79 71 } 80 72 81 LIB_DEBUG_DO( bool validate( alarm_list_t * this ) {82 alarm_node_t ** it = &this->head;83 while( (*it) ) {84 it = &(*it)->next;85 }86 87 return it == this->tail;88 })89 90 73 static inline void insert_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t p ) { 91 verify( !n->next );74 assert( !n->next ); 92 75 if( p == this->tail ) { 93 76 this->tail = &n->next; … … 97 80 } 98 81 *p = n; 99 100 verify( validate( this ) );101 82 } 102 83 … … 108 89 109 90 insert_at( this, n, it ); 110 111 verify( validate( this ) );112 91 } 113 92 … … 121 100 head->next = NULL; 122 101 } 123 verify( validate( this ) );124 102 return head; 125 103 } … … 127 105 static inline void remove_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t it ) { 128 106 verify( it ); 129 verify( (*it) == n );107 verify( (*it)->next == n ); 130 108 131 (*it) = n->next;109 (*it)->next = n->next; 132 110 if( !n-> next ) { 133 111 this->tail = it; 134 112 } 135 113 n->next = NULL; 136 137 verify( validate( this ) );138 114 } 139 115 140 116 static inline void remove( alarm_list_t * this, alarm_node_t * n ) { 141 117 alarm_node_t ** it = &this->head; 142 while( (*it) && (*it) != n ) {118 while( (*it) && (*it)->next != n ) { 143 119 it = &(*it)->next; 144 120 } 145 121 146 verify( validate( this ) );147 148 122 if( *it ) { remove_at( this, n, it ); } 149 150 verify( validate( this ) );151 123 } 152 124 153 125 void register_self( alarm_node_t * this ) { 154 126 disable_interrupts(); 155 verify( !systemProcessor->pending_alarm );156 lock( &systemProcessor->alarm_lock , __PRETTY_FUNCTION__);127 assert( !systemProcessor->pending_alarm ); 128 lock( &systemProcessor->alarm_lock ); 157 129 { 158 verify( validate( &systemProcessor->alarms ) );159 bool first = !systemProcessor->alarms.head;160 161 130 insert( &systemProcessor->alarms, this ); 162 131 if( systemProcessor->pending_alarm ) { 163 132 tick_preemption(); 164 133 } 165 if( first ) {166 __kernel_set_timer( systemProcessor->alarms.head->alarm - __kernel_get_time() );167 }168 134 } 169 135 unlock( &systemProcessor->alarm_lock ); 170 136 this->set = true; 171 enable_interrupts( __PRETTY_FUNCTION__);137 enable_interrupts(); 172 138 } 173 139 174 140 void unregister_self( alarm_node_t * this ) { 175 // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : unregister %p start\n", this );176 141 disable_interrupts(); 177 lock( &systemProcessor->alarm_lock, __PRETTY_FUNCTION__ ); 178 { 179 verify( validate( &systemProcessor->alarms ) ); 180 remove( &systemProcessor->alarms, this ); 181 } 142 lock( &systemProcessor->alarm_lock ); 143 remove( &systemProcessor->alarms, this ); 182 144 unlock( &systemProcessor->alarm_lock ); 183 145 disable_interrupts(); 184 146 this->set = false; 185 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Kernel : unregister %p end\n", this );186 147 }
Note:
See TracChangeset
for help on using the changeset viewer.