Changeset fece3d9 for libcfa/src/concurrency/locks.cfa
- Timestamp:
- May 10, 2023, 2:46:05 PM (16 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 8fd1b7c
- Parents:
- e50fce1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
re50fce1 rfece3d9 171 171 } 172 172 173 size_t on_wait( blocking_lock & this ) with( this ) {173 size_t on_wait( blocking_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) with( this ) { 174 174 lock( lock __cfaabi_dbg_ctx2 ); 175 175 /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this ); … … 184 184 unlock( lock ); 185 185 186 p ark();186 pre_park_then_park( pp_fn, pp_datum ); 187 187 188 188 return ret; … … 396 396 } 397 397 398 static size_t block_and_get_recursion( info_thread(L) & i ) {398 static size_t block_and_get_recursion( info_thread(L) & i, __cfa_pre_park pp_fn, void * pp_datum ) { 399 399 size_t recursion_count = 0; 400 400 if ( i.lock ) { 401 401 // if lock was passed get recursion count to reset to after waking thread 402 recursion_count = on_wait( *i.lock ); // this call blocks403 } else p ark();402 recursion_count = on_wait( *i.lock, pp_fn, pp_datum ); // this call blocks 403 } else pre_park_then_park( pp_fn, pp_datum ); 404 404 return recursion_count; 405 405 } 406 static size_t block_and_get_recursion( info_thread(L) & i ) { return block_and_get_recursion( i, pre_park_noop, 0p ); } 406 407 407 408 // helper for wait()'s' with no timeout … … 424 425 queue_info_thread( this, i ); 425 426 427 static void cond_alarm_register( void * node_ptr ) { register_self( (alarm_node_t *)node_ptr ); } 428 426 429 // helper for wait()'s' with a timeout 427 430 static void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) { … … 433 436 434 437 // registers alarm outside cond lock to avoid deadlock 435 register_self( &node_wrap.alarm_node );438 // register_self( &node_wrap.alarm_node ); 436 439 437 440 // blocks here 438 size_t recursion_count = block_and_get_recursion( info );441 size_t recursion_count = block_and_get_recursion( info, cond_alarm_register, (void *)(&node_wrap.alarm_node) ); 439 442 // park(); 440 443 … … 503 506 info_thread( L ) i = { active_thread(), info, &l }; 504 507 insert_last( blocked_threads, i ); 505 size_t recursion_count = on_wait( *i.lock ); // blocks here508 size_t recursion_count = on_wait( *i.lock, pre_park_noop, 0p ); // blocks here 506 509 // park( ); 507 510 on_wakeup(*i.lock, recursion_count); … … 552 555 // return recursion_count; 553 556 // } 554 555 557 556 558 static void queue_info_thread_timeout( pthread_cond_var(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) { … … 562 564 563 565 // registers alarm outside cond lock to avoid deadlock 564 register_self( &node_wrap.alarm_node );566 // register_self( &node_wrap.alarm_node ); // C_TODO: fix race: registers itself and then alarm handler calls on_notify before block_and_get_recursion is run 565 567 566 568 // blocks here 567 size_t recursion_count = block_and_get_recursion( info );569 size_t recursion_count = block_and_get_recursion( info, cond_alarm_register, (void *)(&node_wrap.alarm_node) ); 568 570 // park(); 569 571
Note: See TracChangeset
for help on using the changeset viewer.