- File:
-
- 1 edited
-
libcfa/src/concurrency/locks.hfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
rd30e3eb r8a97248 253 253 static inline void on_wakeup(clh_lock & this, size_t recursion ) { lock(this); } 254 254 255 255 256 //----------------------------------------------------------------------------- 256 257 // Exponential backoff then block lock … … 271 272 this.lock_value = 0; 272 273 } 274 static 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; 273 277 274 278 static 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; 276 283 } 277 284 … … 279 286 280 287 static 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; 282 292 } 283 293 284 294 static 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 ); 292 302 park( ); 293 303 return true; … … 297 307 size_t compare_val = 0; 298 308 int spin = 4; 299 300 309 // linear backoff 301 310 for( ;; ) { … … 315 324 static inline void unlock(exp_backoff_then_block_lock & this) with(this) { 316 325 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 ); 321 330 } 322 331
Note:
See TracChangeset
for help on using the changeset viewer.