- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
rfece3d9 rbeeff61e 44 44 // - change messy big blocking lock from inheritance to composition to remove need for flags 45 45 46 typedef void (*__cfa_pre_park)( void * );47 48 static inline void pre_park_noop( void * ) {}49 50 //-----------------------------------------------------------------------------51 // is_blocking_lock52 forall( L & | sized(L) )53 trait is_blocking_lock {54 // For synchronization locks to use when acquiring55 void on_notify( L &, struct thread$ * );56 57 // For synchronization locks to use when releasing58 size_t on_wait( L &, __cfa_pre_park pp_fn, void * pp_datum );59 60 // to set recursion count after getting signalled;61 void on_wakeup( L &, size_t recursion );62 };63 64 static inline void pre_park_then_park( __cfa_pre_park pp_fn, void * pp_datum ) {65 pp_fn( pp_datum );66 park();67 }68 69 46 //----------------------------------------------------------------------------- 70 47 // Semaphore … … 92 69 static inline bool try_lock ( single_acquisition_lock & this ) { return try_lock( (blocking_lock &)this ); } 93 70 static inline void unlock ( single_acquisition_lock & this ) { unlock ( (blocking_lock &)this ); } 94 static inline size_t on_wait ( single_acquisition_lock & this , __cfa_pre_park pp_fn, void * pp_datum ) { return on_wait ( (blocking_lock &)this, pp_fn, pp_datum); }71 static inline size_t on_wait ( single_acquisition_lock & this ) { return on_wait ( (blocking_lock &)this ); } 95 72 static inline void on_wakeup( single_acquisition_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); } 96 73 static inline void on_notify( single_acquisition_lock & this, struct thread$ * t ) { on_notify( (blocking_lock &)this, t ); } … … 109 86 static inline bool try_lock ( owner_lock & this ) { return try_lock( (blocking_lock &)this ); } 110 87 static inline void unlock ( owner_lock & this ) { unlock ( (blocking_lock &)this ); } 111 static inline size_t on_wait ( owner_lock & this , __cfa_pre_park pp_fn, void * pp_datum ) { return on_wait ( (blocking_lock &)this, pp_fn, pp_datum); }88 static inline size_t on_wait ( owner_lock & this ) { return on_wait ( (blocking_lock &)this ); } 112 89 static inline void on_wakeup( owner_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); } 113 90 static inline void on_notify( owner_lock & this, struct thread$ * t ) { on_notify( (blocking_lock &)this, t ); } … … 241 218 242 219 static inline void on_notify( futex_mutex & f, thread$ * t){ unpark(t); } 243 static inline size_t on_wait( futex_mutex & this, __cfa_pre_park pp_fn, void * pp_datum ) { 244 unlock( this ); 245 pre_park_then_park( pp_fn, pp_datum ); 246 return 0; 247 } 220 static inline size_t on_wait( futex_mutex & f ) { unlock(f); park(); return 0; } 248 221 249 222 // to set recursion count after getting signalled; … … 315 288 316 289 static inline void on_notify( go_mutex & f, thread$ * t){ unpark( t ); } 317 static inline size_t on_wait( go_mutex & this, __cfa_pre_park pp_fn, void * pp_datum ) { 318 unlock( this ); 319 pre_park_then_park( pp_fn, pp_datum ); 320 return 0; 321 } 290 static inline size_t on_wait( go_mutex & f ) { unlock( f ); park(); return 0; } 322 291 static inline void on_wakeup( go_mutex & f, size_t recursion ) {} 323 292 … … 393 362 394 363 static inline void on_notify( exp_backoff_then_block_lock & this, struct thread$ * t ) { unpark( t ); } 395 static inline size_t on_wait( exp_backoff_then_block_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { 396 unlock( this ); 397 pre_park_then_park( pp_fn, pp_datum ); 398 return 0; 399 } 364 static inline size_t on_wait( exp_backoff_then_block_lock & this ) { unlock( this ); park(); return 0; } 400 365 static inline void on_wakeup( exp_backoff_then_block_lock & this, size_t recursion ) { lock( this ); } 401 366 … … 454 419 unlock( lock ); 455 420 } 456 static inline size_t on_wait( fast_block_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { 457 unlock( this ); 458 pre_park_then_park( pp_fn, pp_datum ); 459 return 0; 460 } 421 static inline size_t on_wait( fast_block_lock & this) { unlock(this); park(); return 0; } 461 422 static inline void on_wakeup( fast_block_lock & this, size_t recursion ) { } 462 423 … … 536 497 } 537 498 538 static inline void on_notify( 499 static inline void on_notify(simple_owner_lock & this, thread$ * t ) with(this) { 539 500 lock( lock __cfaabi_dbg_ctx2 ); 540 501 // lock held … … 551 512 } 552 513 553 static inline size_t on_wait( simple_owner_lock & this , __cfa_pre_park pp_fn, void * pp_datum) with(this) {514 static inline size_t on_wait( simple_owner_lock & this ) with(this) { 554 515 lock( lock __cfaabi_dbg_ctx2 ); 555 516 /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this ); … … 563 524 active_thread()->link_node = (void *)&node; 564 525 unlock( lock ); 565 566 pre_park_then_park( pp_fn, pp_datum ); 526 park(); 567 527 568 528 return ret; … … 664 624 unpark(t); 665 625 } 666 static inline size_t on_wait( spin_queue_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { 667 unlock( this ); 668 pre_park_then_park( pp_fn, pp_datum ); 669 return 0; 670 } 626 static inline size_t on_wait( spin_queue_lock & this ) { unlock( this ); park(); return 0; } 671 627 static inline void on_wakeup( spin_queue_lock & this, size_t recursion ) { lock( this ); } 672 628 … … 709 665 710 666 static inline void on_notify( mcs_block_spin_lock & this, struct thread$ * t ) { unpark( t ); } 711 static inline size_t on_wait( mcs_block_spin_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { 712 unlock( this ); 713 pre_park_then_park( pp_fn, pp_datum ); 714 return 0; 715 } 667 static inline size_t on_wait( mcs_block_spin_lock & this) { unlock( this ); park(); return 0; } 716 668 static inline void on_wakeup( mcs_block_spin_lock & this, size_t recursion ) {lock( this ); } 717 669 … … 765 717 unpark(t); 766 718 } 767 static inline size_t on_wait( block_spin_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { 768 unlock( this ); 769 pre_park_then_park( pp_fn, pp_datum ); 770 return 0; 771 } 719 static inline size_t on_wait( block_spin_lock & this ) { unlock( this ); park(); return 0; } 772 720 static inline void on_wakeup( block_spin_lock & this, size_t recursion ) with(this) { 773 721 // now we acquire the entire block_spin_lock upon waking up … … 776 724 unlock( lock ); // Now we release the internal fast_spin_lock 777 725 } 726 727 //----------------------------------------------------------------------------- 728 // is_blocking_lock 729 forall( L & | sized(L) ) 730 trait is_blocking_lock { 731 // For synchronization locks to use when acquiring 732 void on_notify( L &, struct thread$ * ); 733 734 // For synchronization locks to use when releasing 735 size_t on_wait( L & ); 736 737 // to set recursion count after getting signalled; 738 void on_wakeup( L &, size_t recursion ); 739 }; 778 740 779 741 //-----------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.