Ignore:
File:
1 edited

Legend:

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

    rd30e3eb r8a97248  
    253253static inline void on_wakeup(clh_lock & this, size_t recursion ) { lock(this); }
    254254
     255
    255256//-----------------------------------------------------------------------------
    256257// Exponential backoff then block lock
     
    271272        this.lock_value = 0;
    272273}
     274static inline void ^?{}( exp_backoff_then_block_lock & this ) {}
     275// static inline void ?{}( exp_backoff_then_block_lock & this, exp_backoff_then_block_lock this2 ) = void;
     276// static inline void ?=?( exp_backoff_then_block_lock & this, exp_backoff_then_block_lock this2 ) = void;
    273277
    274278static inline bool internal_try_lock(exp_backoff_then_block_lock & this, size_t & compare_val) with(this) {
    275         return __atomic_compare_exchange_n(&lock_value, &compare_val, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED);
     279        if (__atomic_compare_exchange_n(&lock_value, &compare_val, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
     280                return true;
     281        }
     282        return false;
    276283}
    277284
     
    279286
    280287static inline bool try_lock_contention(exp_backoff_then_block_lock & this) with(this) {
    281         return !__atomic_exchange_n(&lock_value, 2, __ATOMIC_ACQUIRE);
     288        if (__atomic_exchange_n(&lock_value, 2, __ATOMIC_ACQUIRE) == 0) {
     289                return true;
     290        }
     291        return false;
    282292}
    283293
    284294static inline bool block(exp_backoff_then_block_lock & this) with(this) {
    285     lock( spinlock __cfaabi_dbg_ctx2 );
    286     if (__atomic_load_n( &lock_value, __ATOMIC_SEQ_CST) != 2) {
    287         unlock( spinlock );
    288         return true;
    289     }
    290     insert_last( blocked_threads, *active_thread() );
    291     unlock( spinlock );
     295        lock( spinlock __cfaabi_dbg_ctx2 ); // TODO change to lockfree queue (MPSC)
     296        if (lock_value != 2) {
     297                unlock( spinlock );
     298                return true;
     299        }
     300        insert_last( blocked_threads, *active_thread() );
     301        unlock( spinlock );
    292302        park( );
    293303        return true;
     
    297307        size_t compare_val = 0;
    298308        int spin = 4;
    299 
    300309        // linear backoff
    301310        for( ;; ) {
     
    315324static inline void unlock(exp_backoff_then_block_lock & this) with(this) {
    316325    if (__atomic_exchange_n(&lock_value, 0, __ATOMIC_RELEASE) == 1) return;
    317     lock( spinlock __cfaabi_dbg_ctx2 );
    318     thread$ * t = &try_pop_front( blocked_threads );
    319     unlock( spinlock );
    320     unpark( t );
     326        lock( spinlock __cfaabi_dbg_ctx2 );
     327        thread$ * t = &try_pop_front( blocked_threads );
     328        unlock( spinlock );
     329        unpark( t );
    321330}
    322331
Note: See TracChangeset for help on using the changeset viewer.