Changeset 7d9598d for libcfa/src


Ignore:
Timestamp:
Dec 14, 2022, 12:23:26 PM (17 months ago)
Author:
caparson <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
2dcd80a
Parents:
63be3387
Message:

small lock cleanup

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

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

    r63be3387 r7d9598d  
    414414                #ifdef __CFA_DEBUG__
    415415                        if ( lock_used == 0p ) lock_used = &l;
    416                         else { assert(lock_used == &l); }
     416                        else assert(lock_used == &l);
    417417                #endif
    418418                info_thread( L ) i = { active_thread(), info, &l };
  • libcfa/src/concurrency/locks.hfa

    r63be3387 r7d9598d  
    162162
    163163// to use for FUTEX_WAKE and FUTEX_WAIT (other futex calls will need more params)
    164 static int futex(int *uaddr, int futex_op, int val) {
     164static inline int futex(int *uaddr, int futex_op, int val) {
    165165    return syscall(SYS_futex, uaddr, futex_op, val, NULL, NULL, 0);
    166166}
     
    181181
    182182       
    183         // linear backoff
    184         for( int spin = 4; spin < 1024; spin += spin) {
    185                 state = 0;
    186                 // if unlocked, lock and return
    187                 if (internal_try_lock(this, state)) return;
    188                 if (2 == state) break;
    189                 for (int i = 0; i < spin; i++) Pause();
    190         }
    191         // if (internal_try_lock(this, state)) return;
     183        // // linear backoff omitted for now
     184        // for( int spin = 4; spin < 1024; spin += spin) {
     185        //      state = 0;
     186        //      // if unlocked, lock and return
     187        //      if (internal_try_lock(this, state)) return;
     188        //      if (2 == state) break;
     189        //      for (int i = 0; i < spin; i++) Pause();
     190        // }
     191
     192        // no contention try to acquire
     193        if (internal_try_lock(this, state)) return;
    192194       
    193195        // if not in contended state, set to be in contended state
     
    290292
    291293static inline bool block(linear_backoff_then_block_lock & this) with(this) {
    292         lock( spinlock __cfaabi_dbg_ctx2 );
     294        lock( spinlock __cfaabi_dbg_ctx2 ); // TODO change to lockfree queue (MPSC)
    293295        if (lock_value != 2) {
    294296                unlock( spinlock );
Note: See TracChangeset for help on using the changeset viewer.