Changeset d30e3eb for libcfa/src/concurrency/locks.hfa
- Timestamp:
- Mar 24, 2023, 4:44:46 PM (18 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 1633e04
- Parents:
- de934c7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
rde934c7 rd30e3eb 253 253 static inline void on_wakeup(clh_lock & this, size_t recursion ) { lock(this); } 254 254 255 256 255 //----------------------------------------------------------------------------- 257 256 // Exponential backoff then block lock … … 272 271 this.lock_value = 0; 273 272 } 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;277 273 278 274 static inline bool internal_try_lock(exp_backoff_then_block_lock & this, size_t & compare_val) with(this) { 279 if (__atomic_compare_exchange_n(&lock_value, &compare_val, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { 280 return true; 281 } 282 return false; 275 return __atomic_compare_exchange_n(&lock_value, &compare_val, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); 283 276 } 284 277 … … 286 279 287 280 static inline bool try_lock_contention(exp_backoff_then_block_lock & this) with(this) { 288 if (__atomic_exchange_n(&lock_value, 2, __ATOMIC_ACQUIRE) == 0) { 289 return true; 290 } 291 return false; 281 return !__atomic_exchange_n(&lock_value, 2, __ATOMIC_ACQUIRE); 292 282 } 293 283 294 284 static inline bool block(exp_backoff_then_block_lock & this) with(this) { 295 lock( spinlock __cfaabi_dbg_ctx2 ); // TODO change to lockfree queue (MPSC) 296 if (lock_value!= 2) {297 298 299 300 301 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 ); 302 292 park( ); 303 293 return true; … … 307 297 size_t compare_val = 0; 308 298 int spin = 4; 299 309 300 // linear backoff 310 301 for( ;; ) { … … 324 315 static inline void unlock(exp_backoff_then_block_lock & this) with(this) { 325 316 if (__atomic_exchange_n(&lock_value, 0, __ATOMIC_RELEASE) == 1) return; 326 327 328 329 317 lock( spinlock __cfaabi_dbg_ctx2 ); 318 thread$ * t = &try_pop_front( blocked_threads ); 319 unlock( spinlock ); 320 unpark( t ); 330 321 } 331 322
Note: See TracChangeset
for help on using the changeset viewer.