Changeset b14ec5f
- Timestamp:
- Nov 19, 2021, 11:23:24 AM (2 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- a633f6f
- Parents:
- 34b8cb7 (diff), 84a6e70 (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:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r34b8cb7 rb14ec5f 124 124 static void __wake_one(cluster * cltr); 125 125 126 static voidmark_idle (__cluster_proc_list & idles, processor & proc);126 static bool mark_idle (__cluster_proc_list & idles, processor & proc); 127 127 static void mark_awake(__cluster_proc_list & idles, processor & proc); 128 128 … … 212 212 213 213 // Push self to idle stack 214 mark_idle(this->cltr->procs, * this);214 if(!mark_idle(this->cltr->procs, * this)) continue MAIN_LOOP; 215 215 216 216 // Confirm the ready-queue is empty … … 330 330 // Push self to idle stack 331 331 ready_schedule_unlock(); 332 mark_idle(this->cltr->procs, * this);332 if(!mark_idle(this->cltr->procs, * this)) goto SEARCH; 333 333 ready_schedule_lock(); 334 334 … … 802 802 } 803 803 804 static voidmark_idle(__cluster_proc_list & this, processor & proc) {805 /* paranoid */ verify( ! __preemption_enabled() ); 806 lock( this );804 static bool mark_idle(__cluster_proc_list & this, processor & proc) { 805 /* paranoid */ verify( ! __preemption_enabled() ); 806 if(!try_lock( this )) return false; 807 807 this.idle++; 808 808 /* paranoid */ verify( this.idle <= this.total ); … … 813 813 unlock( this ); 814 814 /* paranoid */ verify( ! __preemption_enabled() ); 815 816 return true; 815 817 } 816 818 -
libcfa/src/concurrency/kernel_private.hfa
r34b8cb7 rb14ec5f 282 282 } 283 283 284 static inline bool try_lock(__cluster_proc_list & this) { 285 /* paranoid */ verify( ! __preemption_enabled() ); 286 287 // Start by locking the global RWlock so that we know no-one is 288 // adding/removing processors while we mess with the idle lock 289 ready_schedule_lock(); 290 291 // Simple counting lock, acquired, acquired by incrementing the counter 292 // to an odd number 293 uint64_t l = this.lock; 294 if( 295 (0 == (l % 2)) 296 && __atomic_compare_exchange_n(&this.lock, &l, l + 1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) 297 ) { 298 // success 299 /* paranoid */ verify( ! __preemption_enabled() ); 300 return true; 301 } 302 303 // failed to lock 304 ready_schedule_unlock(); 305 306 /* paranoid */ verify( ! __preemption_enabled() ); 307 return false; 308 } 309 284 310 static inline void unlock(__cluster_proc_list & this) { 285 311 /* paranoid */ verify( ! __preemption_enabled() );
Note: See TracChangeset
for help on using the changeset viewer.