Changeset 822ae48
- Timestamp:
- Nov 17, 2025, 9:02:57 PM (4 days ago)
- Branches:
- master
- Children:
- 86b418f
- Parents:
- 771a4f7
- Location:
- libcfa/src/concurrency
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r771a4f7 r822ae48 638 638 } 639 639 640 thread$ * V( semaphore & sem, const bool doUnpark) with( sem ) {640 bool V( semaphore & sem ) with( sem ) { 641 641 thread$ * thrd = 0p; 642 642 lock( lock$ __cfaabi_dbg_ctx2 ); … … 646 646 } 647 647 unlock( lock$ ); 648 if ( doUnpark ) unpark( thrd ); // make new owner 649 return thrd; 650 } 651 652 bool V( semaphore & sem, size_t diff ) with( sem ) { 653 thread$ * thrd = 0p; 648 if ( true ) unpark( thrd ); // make new owner 649 return thrd != 0p; 650 } 651 652 size_t V( semaphore & sem, size_t count ) with( sem ) { 654 653 lock( lock$ __cfaabi_dbg_ctx2 ); 655 size_t release = max( (size_t)-count$, diff);656 count$ += diff;654 size_t release = max( (size_t)-count$, count ); 655 count$ += count; 657 656 for ( release ) unpark( pop_head( waiting$ ) ); 658 657 unlock( lock$ ); 659 return thrd != 0p;660 } 658 return release; 659 } -
libcfa/src/concurrency/locks.hfa
r771a4f7 r822ae48 11 11 // Created On : Thu Jan 21 19:46:50 2021 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Wed Nov 5 10:27:45 202514 // Update Count : 6 113 // Last Modified On : Mon Nov 17 20:48:55 2025 14 // Update Count : 63 15 15 // 16 16 … … 85 85 86 86 struct semaphore { 87 // PRIVATE88 87 ssize_t count$; // - => # waiting threads, 0 => block, + => acquire 89 88 __spinlock_t lock$; // protect blocking-lock critical sections … … 99 98 bool try_P( semaphore & sem ); 100 99 static inline bool P( semaphore & sem, semaphore & lock, uintptr_t shadow ) { active_thread()->shadow$ = shadow; return P( sem, lock ); } 101 thread$ * V( semaphore & sem, const bool doUnpark = true ); 102 static inline bool V( semaphore & sem ) with( sem ) { return V( sem, true ) != 0p; } 103 bool V( semaphore & sem, size_t count ); 100 bool V( semaphore & sem ); 101 size_t V( semaphore & sem, size_t count ); 104 102 static inline uintptr_t front( semaphore & sem ) with( sem ) { // return shadow information for first waiting thread 105 103 #ifdef __CFA_DEBUG__
Note:
See TracChangeset
for help on using the changeset viewer.