Changeset 822ae48


Ignore:
Timestamp:
Nov 17, 2025, 9:02:57 PM (4 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
86b418f
Parents:
771a4f7
Message:

update semaphore lock

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/locks.cfa

    r771a4f7 r822ae48  
    638638}
    639639
    640 thread$ * V( semaphore & sem, const bool doUnpark ) with( sem ) {
     640bool V( semaphore & sem ) with( sem ) {
    641641        thread$ * thrd = 0p;
    642642        lock( lock$ __cfaabi_dbg_ctx2 );
     
    646646        }
    647647        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
     652size_t V( semaphore & sem, size_t count ) with( sem ) {
    654653        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;
    657656        for ( release ) unpark( pop_head( waiting$ ) );
    658657        unlock( lock$ );
    659         return thrd != 0p;
    660 }
     658        return release;
     659}
  • libcfa/src/concurrency/locks.hfa

    r771a4f7 r822ae48  
    1111// Created On       : Thu Jan 21 19:46:50 2021
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Wed Nov  5 10:27:45 2025
    14 // Update Count     : 61
     13// Last Modified On : Mon Nov 17 20:48:55 2025
     14// Update Count     : 63
    1515//
    1616
     
    8585
    8686struct semaphore {
    87         // PRIVATE
    8887        ssize_t count$;                                                                          // - => # waiting threads, 0 => block, + => acquire
    8988        __spinlock_t lock$;                                                                      // protect blocking-lock critical sections
     
    9998bool try_P( semaphore & sem );
    10099static 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 );
     100bool V( semaphore & sem );
     101size_t V( semaphore & sem, size_t count );
    104102static inline uintptr_t front( semaphore & sem ) with( sem ) { // return shadow information for first waiting thread
    105103        #ifdef __CFA_DEBUG__
Note: See TracChangeset for help on using the changeset viewer.