- File:
-
- 1 edited
-
src/libcfa/concurrency/monitor.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor.c
rbe3d020 r44264c5 137 137 } 138 138 139 void ?{}(__condition_node_t * this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info ) { 140 this->waiting_thread = waiting_thread; 141 this->count = count; 142 this->next = NULL; 143 this->user_info = user_info; 144 } 145 146 void ?{}(__condition_criterion_t * this ) { 147 this->ready = false; 148 this->target = NULL; 149 this->owner = NULL; 150 this->next = NULL; 151 } 152 153 void ?{}(__condition_criterion_t * this, monitor_desc * target, __condition_node_t * owner ) { 154 this->ready = false; 155 this->target = target; 156 this->owner = owner; 157 this->next = NULL; 139 void debug_break() __attribute__(( noinline )) 140 { 141 158 142 } 159 143 160 144 //----------------------------------------------------------------------------- 161 145 // Internal scheduling 162 void wait( condition * this , uintptr_t user_info = 0) {146 void wait( condition * this ) { 163 147 LIB_DEBUG_PRINT_SAFE("Waiting\n"); 164 148 … … 176 160 LIB_DEBUG_PRINT_SAFE("count %i\n", count); 177 161 178 __condition_node_t waiter = { this_thread(), count, user_info }; 162 __condition_node_t waiter; 163 waiter.waiting_thread = this_thread(); 164 waiter.count = count; 165 waiter.next = NULL; 179 166 180 167 __condition_criterion_t criteria[count]; 181 168 for(int i = 0; i < count; i++) { 182 (&criteria[i]){ this->monitors[i], &waiter }; 169 criteria[i].ready = false; 170 criteria[i].target = this->monitors[i]; 171 criteria[i].owner = &waiter; 172 criteria[i].next = NULL; 183 173 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] ); 184 174 } … … 212 202 ScheduleInternal( locks, count, threads, thread_count ); 213 203 204 debug_break(); 214 205 //WE WOKE UP 215 206 … … 221 212 } 222 213 223 boolsignal( condition * this ) {224 if( is_empty( this )) {214 void signal( condition * this ) { 215 if( !this->blocked.head ) { 225 216 LIB_DEBUG_PRINT_SAFE("Nothing to signal\n"); 226 return false;217 return; 227 218 } 228 219 … … 266 257 //Release 267 258 unlock_all( this->monitors, count ); 268 269 return true; 270 } 271 272 bool signal_block( condition * this ) { 259 } 260 261 void signal_block( condition * this ) { 273 262 if( !this->blocked.head ) { 274 263 LIB_DEBUG_PRINT_SAFE("Nothing to signal\n"); 275 return false;264 return; 276 265 } 277 266 … … 287 276 288 277 //create creteria 289 __condition_node_t waiter = { this_thread(), count, 0 }; 278 __condition_node_t waiter; 279 waiter.waiting_thread = this_thread(); 280 waiter.count = count; 281 waiter.next = NULL; 290 282 291 283 __condition_criterion_t criteria[count]; 292 284 for(int i = 0; i < count; i++) { 293 (&criteria[i]){ this->monitors[i], &waiter };294 285 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] ); 286 criteria[i].ready = false; 287 criteria[i].owner = &waiter; 288 criteria[i].next = NULL; 289 criteria[i].target = this->monitors[i]; 295 290 push( &criteria[i].target->signal_stack, &criteria[i] ); 296 291 } … … 308 303 309 304 LIB_DEBUG_PRINT_SAFE( "Waiting on signal block\n" ); 305 debug_break(); 310 306 311 307 //Everything is ready to go to sleep 312 308 ScheduleInternal( locks, count, &signallee, 1 ); 313 309 310 debug_break(); 314 311 LIB_DEBUG_PRINT_SAFE( "Back from signal block\n" ); 315 312 … … 318 315 restore_recursion( this->monitors, recursions, count ); 319 316 unlock_all( locks, count ); 320 321 return true;322 }323 324 uintptr_t front( condition * this ) {325 LIB_DEBUG_DO(326 if( is_empty(this) ) {327 abortf( "Attempt to access user data on an empty condition.\n"328 "Possible cause is not checking if the condition is empty before reading stored data." );329 }330 );331 return this->blocked.head->user_info;332 317 } 333 318
Note:
See TracChangeset
for help on using the changeset viewer.