Changeset 490d17e0 for libcfa/src/concurrency
- Timestamp:
- Jun 2, 2022, 3:10:17 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 305aaef
- Parents:
- fb63c70
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
rfb63c70 r490d17e0 366 366 static inline void ?=?( simple_owner_lock & this, simple_owner_lock this2 ) = void; 367 367 368 static inline void lock(simple_owner_lock & this) with(this) {369 if (owner == active_thread()) {370 recursion_count++;371 return;372 }373 lock( lock __cfaabi_dbg_ctx2 );374 375 if (owner != 0p) {376 insert_last( blocked_threads, *active_thread() );377 unlock( lock );378 park( );379 return;380 }381 owner = active_thread();382 recursion_count = 1;383 unlock( lock );384 }385 386 void pop_and_set_new_owner( simple_owner_lock & this ) with( this ) {387 thread$ * t = &try_pop_front( blocked_threads );388 owner = t;389 recursion_count = ( t ? 1 : 0 );390 unpark( t );391 }392 393 static inline void unlock(simple_owner_lock & this) with(this) {394 lock( lock __cfaabi_dbg_ctx2 );395 /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this );396 /* paranoid */ verifyf( owner == active_thread(), "Thread %p other than the owner %p attempted to release owner lock %p", owner, active_thread(), &this );397 // if recursion count is zero release lock and set new owner if one is waiting398 recursion_count--;399 if ( recursion_count == 0 ) {400 pop_and_set_new_owner( this );401 }402 unlock( lock );403 }404 405 static inline void on_notify(simple_owner_lock & this, struct thread$ * t ) with(this) {406 lock( lock __cfaabi_dbg_ctx2 );407 // lock held408 if ( owner != 0p ) {409 insert_last( blocked_threads, *t );410 unlock( lock );411 }412 // lock not held413 else {414 owner = t;415 recursion_count = 1;416 unpark( t );417 unlock( lock );418 }419 }420 421 static inline size_t on_wait(simple_owner_lock & this) with(this) {422 lock( lock __cfaabi_dbg_ctx2 );423 /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this );424 /* paranoid */ verifyf( owner == active_thread(), "Thread %p other than the owner %p attempted to release owner lock %p", owner, active_thread(), &this );425 426 size_t ret = recursion_count;427 428 pop_and_set_new_owner( this );429 430 unlock( lock );431 return ret;432 }433 434 static inline void on_wakeup(simple_owner_lock & this, size_t recursion ) with(this) { recursion_count = recursion; }435 436 368 //----------------------------------------------------------------------------- 437 369 // Spin Queue Lock
Note: See TracChangeset
for help on using the changeset viewer.