Changeset 5a05946 for libcfa/src/concurrency/locks.cfa
- Timestamp:
- May 15, 2023, 1:14:42 PM (16 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 629c95a
- Parents:
- 8cb06b6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r8cb06b6 r5a05946 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // locks. hfa -- LIBCFATHREAD7 // locks.cfa -- LIBCFATHREAD 8 8 // Runtime locks that used with the runtime thread system. 9 9 // … … 113 113 return ret; 114 114 } 115 116 // static void pop_and_set_new_owner( blocking_lock & this ) with( this ) {117 // thread$ * t = &try_pop_front( blocked_threads );118 // owner = t;119 // recursion_count = ( t ? 1 : 0 );120 // if ( t ) wait_count--;121 // unpark( t );122 // }123 115 124 116 static inline void pop_node( blocking_lock & this ) with( this ) { … … 388 380 insert_last( blocked_threads, *i ); 389 381 count++; 390 // size_t recursion_count = 0;391 // if (i->lock) {392 // // if lock was passed get recursion count to reset to after waking thread393 // recursion_count = on_wait( *i->lock );394 // }395 // return recursion_count;396 382 } 397 383 398 384 static size_t block_and_get_recursion( info_thread(L) & i, __cfa_pre_park pp_fn, void * pp_datum ) { 399 385 size_t recursion_count = 0; 400 if ( i.lock ) { 401 // if lock was passed get recursion count to reset to after waking thread 386 if ( i.lock ) // if lock was passed get recursion count to reset to after waking thread 402 387 recursion_count = on_wait( *i.lock, pp_fn, pp_datum ); // this call blocks 403 } else pre_park_then_park( pp_fn, pp_datum ); 388 else 389 pre_park_then_park( pp_fn, pp_datum ); 404 390 return recursion_count; 405 391 } … … 410 396 lock( lock __cfaabi_dbg_ctx2 ); 411 397 enqueue_thread( this, &i ); 412 // size_t recursion_count = queue_and_get_recursion( this, &i );413 398 unlock( lock ); 414 399 415 400 // blocks here 416 401 size_t recursion_count = block_and_get_recursion( i ); 417 // park( );418 402 419 403 // resets recursion count here after waking … … 431 415 lock( lock __cfaabi_dbg_ctx2 ); 432 416 enqueue_thread( this, &info ); 433 // size_t recursion_count = queue_and_get_recursion( this, &info );434 417 alarm_node_wrap(L) node_wrap = { t, 0`s, callback, &this, &info }; 435 418 unlock( lock ); 436 419 437 // registers alarm outside cond lock to avoid deadlock 438 // register_self( &node_wrap.alarm_node ); 439 440 // blocks here 420 // blocks here and registers alarm node before blocking after releasing locks to avoid deadlock 441 421 size_t recursion_count = block_and_get_recursion( info, cond_alarm_register, (void *)(&node_wrap.alarm_node) ); 442 422 // park(); … … 548 528 bool empty ( pthread_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty; } 549 529 550 // static size_t queue_and_get_recursion( pthread_cond_var(L) & this, info_thread(L) * i ) with(this) {551 // // add info_thread to waiting queue552 // insert_last( blocked_threads, *i );553 // size_t recursion_count = 0;554 // recursion_count = on_wait( *i->lock );555 // return recursion_count;556 // }557 558 530 static void queue_info_thread_timeout( pthread_cond_var(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) { 559 531 lock( lock __cfaabi_dbg_ctx2 ); 560 // size_t recursion_count = queue_and_get_recursion(this, &info);561 532 insert_last( blocked_threads, info ); 562 533 pthread_alarm_node_wrap(L) node_wrap = { t, 0`s, callback, &this, &info }; 563 534 unlock( lock ); 564 535 565 // registers alarm outside cond lock to avoid deadlock 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 567 568 // blocks here 536 // blocks here and registers alarm node before blocking after releasing locks to avoid deadlock 569 537 size_t recursion_count = block_and_get_recursion( info, cond_alarm_register, (void *)(&node_wrap.alarm_node) ); 570 // park(); 571 572 // unregisters alarm so it doesn't go off if this happens first 538 539 // unregisters alarm so it doesn't go off if signal happens first 573 540 unregister_self( &node_wrap.alarm_node ); 574 541 … … 585 552 info_thread( L ) i = { active_thread(), info, &l }; 586 553 insert_last( blocked_threads, i ); 587 // size_t recursion_count = queue_and_get_recursion( this, &i );588 554 unlock( lock ); 589 555 590 556 // blocks here 591 557 size_t recursion_count = block_and_get_recursion( i ); 592 // park(); 558 593 559 on_wakeup( *i.lock, recursion_count ); 594 560 } … … 679 645 return thrd != 0p; 680 646 } 647
Note: See TracChangeset
for help on using the changeset viewer.