Changeset bbe3719
- Timestamp:
- Sep 3, 2021, 9:52:04 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 65502d8
- Parents:
- 0a55a53
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
r0a55a53 rbbe3719 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 //----------------------------------------------------------------------------- -
libcfa/src/concurrency/mutex_stmt.hfa
r0a55a53 rbbe3719 40 40 } 41 41 } 42 43 static inline L * __get_pointer( L & lock ) {44 return &lock;45 }46 42 } -
src/Concurrency/Keywords.cc
r0a55a53 rbbe3719 1208 1208 new ListInit( 1209 1209 map_range < std::list<Initializer*> > ( args, [](Expression * var ){ 1210 return new SingleInit( new UntypedExpr( 1211 new NameExpr( "__get_pointer" ), 1212 { var } 1213 ) ); 1210 return new SingleInit( new AddressExpr( var ) ); 1214 1211 }) 1215 1212 ) -
tests/concurrent/mutexstmt/locks.cfa
r0a55a53 rbbe3719 4 4 const unsigned int num_times = 10000; 5 5 6 owner_lock m1, m2, m3, m4, m5;6 single_acquisition_lock m1, m2, m3, m4, m5; 7 7 8 8 thread T_Mutex {}; … … 65 65 printf("Start Test: single lock mutual exclusion\n"); 66 66 { 67 T_Mutex t[1 ];67 T_Mutex t[10]; 68 68 } 69 69 printf("End Test: single lock mutual exclusion\n");
Note: See TracChangeset
for help on using the changeset viewer.