Changeset 5a40e4e for libcfa/src/concurrency/locks.hfa
- Timestamp:
- Sep 9, 2021, 3:56:32 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- d0b9247
- Parents:
- dd1cc02 (diff), d8d512e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
rdd1cc02 r5a40e4e 324 324 } 325 325 326 // linear backoff bounded by spin_count327 spin = spin_start;328 int spin_counter = 0;329 int yield_counter = 0;330 for ( ;; ) {331 if(try_lock_contention(this)) return true;332 if(spin_counter < spin_count) {333 for (int i = 0; i < spin; i++) Pause();334 if (spin < spin_end) spin += spin;335 else spin_counter++;336 } else if (yield_counter < yield_count) {337 // after linear backoff yield yield_count times338 yield_counter++;339 yield();340 } else { break; }341 }342 343 // block until signalled344 while (block(this)) if(try_lock_contention(this)) return true;345 346 // this should never be reached as block(this) always returns true347 return false;348 }349 350 static inline bool lock_improved(linear_backoff_then_block_lock & this) with(this) {351 // if owner just return352 if (active_thread() == owner) return true;353 size_t compare_val = 0;354 int spin = spin_start;355 // linear backoff356 for( ;; ) {357 compare_val = 0;358 if (internal_try_lock(this, compare_val)) return true;359 if (2 == compare_val) break;360 for (int i = 0; i < spin; i++) Pause();361 if (spin >= spin_end) break;362 spin += spin;363 }364 365 // linear backoff bounded by spin_count366 spin = spin_start;367 int spin_counter = 0;368 int yield_counter = 0;369 for ( ;; ) {370 compare_val = 0;371 if(internal_try_lock(this, compare_val)) return true;372 if (2 == compare_val) break;373 if(spin_counter < spin_count) {374 for (int i = 0; i < spin; i++) Pause();375 if (spin < spin_end) spin += spin;376 else spin_counter++;377 } else if (yield_counter < yield_count) {378 // after linear backoff yield yield_count times379 yield_counter++;380 yield();381 } else { break; }382 }383 384 326 if(2 != compare_val && try_lock_contention(this)) return true; 385 327 // block until signalled … … 402 344 static inline void on_notify(linear_backoff_then_block_lock & this, struct thread$ * t ) { unpark(t); } 403 345 static inline size_t on_wait(linear_backoff_then_block_lock & this) { unlock(this); return 0; } 404 static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock _improved(this); }346 static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock(this); } 405 347 406 348 //-----------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.