Changeset 5a40e4e for libcfa/src/concurrency
- Timestamp:
- Sep 9, 2021, 3:56:32 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- 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. - Location:
- libcfa/src/concurrency
- Files:
-
- 1 added
- 5 edited
-
kernel/startup.cfa (modified) (2 diffs)
-
locks.hfa (modified) (2 diffs)
-
monitor.cfa (modified) (2 diffs)
-
monitor.hfa (modified) (2 diffs)
-
mutex_stmt.hfa (added)
-
thread.cfa (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel/startup.cfa
rdd1cc02 r5a40e4e 235 235 236 236 register_tls( mainProcessor ); 237 mainThread->last_cpu = __kernel_getcpu(); 237 238 238 239 //initialize the global state variables … … 478 479 state = Start; 479 480 self_cor{ info }; 480 last_cpu = __kernel_getcpu();481 481 curr_cor = &self_cor; 482 482 curr_cluster = mainCluster; -
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 //----------------------------------------------------------------------------- -
libcfa/src/concurrency/monitor.cfa
rdd1cc02 r5a40e4e 367 367 368 368 // __cfaabi_dbg_print_safe( "MGUARD : entered\n" ); 369 } 370 371 void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count ) { 372 this{ m, count, 0p }; 369 373 } 370 374 … … 986 990 } 987 991 992 //----------------------------------------------------------------------------- 993 // Enter routine for mutex stmt 994 // Can't be accepted since a mutex stmt is effectively an anonymous routine 995 // Thus we do not need a monitor group 996 void lock( monitor$ * this ) { 997 thread$ * thrd = active_thread(); 998 999 // Lock the monitor spinlock 1000 lock( this->lock __cfaabi_dbg_ctx2 ); 1001 1002 __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); 1003 1004 if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) { 1005 abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this ); 1006 } 1007 else if( !this->owner ) { 1008 // No one has the monitor, just take it 1009 __set_owner( this, thrd ); 1010 1011 __cfaabi_dbg_print_safe( "Kernel : mon is free \n" ); 1012 } 1013 else if( this->owner == thrd) { 1014 // We already have the monitor, just note how many times we took it 1015 this->recursion += 1; 1016 1017 __cfaabi_dbg_print_safe( "Kernel : mon already owned \n" ); 1018 } 1019 else { 1020 __cfaabi_dbg_print_safe( "Kernel : blocking \n" ); 1021 1022 // Some one else has the monitor, wait in line for it 1023 /* paranoid */ verify( thrd->link.next == 0p ); 1024 append( this->entry_queue, thrd ); 1025 /* paranoid */ verify( thrd->link.next == 1p ); 1026 1027 unlock( this->lock ); 1028 park(); 1029 1030 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); 1031 1032 /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this ); 1033 return; 1034 } 1035 1036 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); 1037 1038 /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this ); 1039 /* paranoid */ verify( this->lock.lock ); 1040 1041 // Release the lock and leave 1042 unlock( this->lock ); 1043 return; 1044 } 1045 1046 // Leave routine for mutex stmt 1047 // Is just a wrapper around __leave for the is_lock trait to see 1048 void unlock( monitor$ * this ) { __leave( this ); } 1049 988 1050 // Local Variables: // 989 1051 // mode: c // -
libcfa/src/concurrency/monitor.hfa
rdd1cc02 r5a40e4e 48 48 49 49 void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count, void (*func)() ); 50 void ?{}( monitor_guard_t & this, monitor$ ** m, __lock_size_t count ); 50 51 void ^?{}( monitor_guard_t & this ); 51 52 … … 148 149 void __waitfor_internal( const __waitfor_mask_t & mask, int duration ); 149 150 151 // lock and unlock routines for mutex statements to use 152 void lock( monitor$ * this ); 153 void unlock( monitor$ * this ); 154 150 155 // Local Variables: // 151 156 // mode: c // -
libcfa/src/concurrency/thread.cfa
rdd1cc02 r5a40e4e 34 34 preempted = __NO_PREEMPTION; 35 35 corctx_flag = false; 36 disable_interrupts(); 36 37 last_cpu = __kernel_getcpu(); 38 enable_interrupts(); 37 39 curr_cor = &self_cor; 38 40 self_mon.owner = &this;
Note:
See TracChangeset
for help on using the changeset viewer.