Changeset b7763da
- Timestamp:
- Jul 5, 2021, 2:21:50 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 55ad35c, ee23a8d
- Parents:
- d5f6a14
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified libcfa/src/concurrency/locks.hfa ¶
rd5f6a14 rb7763da 274 274 this.yield_count = yield_count; 275 275 } 276 static inline void ?{}( linear_backoff_then_block_lock & this ) { this{4, 1024, 16, 0}; } 276 static inline void ?{}( linear_backoff_then_block_lock & this ) { this{4, 1024, 16, 0}; 277 printf("lock_ctor: %p\n", &this); } 277 278 static inline void ^?{}( linear_backoff_then_block_lock & this ) {} 278 279 … … 346 347 } 347 348 349 static inline bool lock_improved(linear_backoff_then_block_lock & this) with(this) { 350 // if owner just return 351 if (active_thread() == owner) return true; 352 size_t compare_val = 0; 353 int spin = spin_start; 354 // linear backoff 355 for( ;; ) { 356 compare_val = 0; 357 if (internal_try_lock(this, compare_val)) return true; 358 if (2 == compare_val) break; 359 for (int i = 0; i < spin; i++) Pause(); 360 if (spin >= spin_end) break; 361 spin += spin; 362 } 363 364 // linear backoff bounded by spin_count 365 spin = spin_start; 366 int spin_counter = 0; 367 int yield_counter = 0; 368 for ( ;; ) { 369 compare_val = 0; 370 if(internal_try_lock(this, compare_val)) return true; 371 if (2 == compare_val) break; 372 if(spin_counter < spin_count) { 373 for (int i = 0; i < spin; i++) Pause(); 374 if (spin < spin_end) spin += spin; 375 else spin_counter++; 376 } else if (yield_counter < yield_count) { 377 // after linear backoff yield yield_count times 378 yield_counter++; 379 yield(); 380 } else { break; } 381 } 382 383 if(2 != compare_val && try_lock_contention(this)) return true; 384 // block until signalled 385 while (block(this)) if(try_lock_contention(this)) return true; 386 387 // this should never be reached as block(this) always returns true 388 return false; 389 } 390 348 391 static inline void unlock(linear_backoff_then_block_lock & this) with(this) { 349 392 verify(lock_value > 0); … … 358 401 static inline void on_notify(linear_backoff_then_block_lock & this, struct $thread * t ) { unpark(t); } 359 402 static inline size_t on_wait(linear_backoff_then_block_lock & this) { unlock(this); return 0; } 360 static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock (this); }403 static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock_improved(this); } 361 404 362 405 //-----------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.