Changeset b94579a for libcfa/src/concurrency/locks.cfa
- Timestamp:
- Nov 7, 2025, 8:30:59 AM (5 days ago)
- Branches:
- master
- Parents:
- 0048327
- File:
-
- 1 edited
-
libcfa/src/concurrency/locks.cfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r0048327 rb94579a 587 587 // Semaphore, counting 588 588 589 // PRIVATE590 591 thread$ * V( semaphore & sem, const bool doUnpark ) with( sem ) {592 thread$ * thrd = 0p;593 lock( lock$ __cfaabi_dbg_ctx2 );594 count$ += 1;595 if ( count$ <= 0 ) {596 thrd = pop_head( waiting$ ); // remove task at head of waiting list597 }598 unlock( lock$ );599 if ( doUnpark ) unpark( thrd ); // make new owner600 return thrd;601 }602 603 // PUBLIC604 605 589 void ?{}( semaphore & sem, ssize_t count = 1 ) with( sem ) { 606 590 count$ = count; … … 613 597 count$ -= 1; 614 598 if ( count$ < 0 ) { // in use ? 615 append( waiting$, active_thread() ); // queue current task616 unlock( lock$ ); // atomically release spin lock and block599 append( waiting$, active_thread() ); // queue current task 600 unlock( lock$ ); // atomically release spin lock and block 617 601 park(); 618 602 return false; … … 629 613 } // if 630 614 } else { 631 V( sem ); // V othersemaphore615 V( lock ); // V mutex semaphore 632 616 count$ -= 1; 633 617 } // if … … 654 638 } 655 639 656 bool V( semaphore & sem) with( sem ) {640 thread$ * V( semaphore & sem, const bool doUnpark ) with( sem ) { 657 641 thread$ * thrd = 0p; 658 642 lock( lock$ __cfaabi_dbg_ctx2 ); … … 662 646 } 663 647 unlock( lock$ ); 664 if ( true ) unpark( thrd ); // make new owner 665 // thread$ * thrd = V(sem, true); 666 return thrd != 0p; 648 if ( doUnpark ) unpark( thrd ); // make new owner 649 return thrd; 667 650 } 668 651
Note:
See TracChangeset
for help on using the changeset viewer.