Changeset e235429 for libcfa/src
- Timestamp:
- Oct 1, 2020, 1:52:53 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b4b63e8
- Parents:
- 038110a
- Location:
- libcfa/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/locks.hfa
r038110a re235429 164 164 165 165 struct $thread; 166 extern void park( __cfaabi_dbg_ctx_param);167 extern void unpark( struct $thread * this __cfaabi_dbg_ctx_param2);166 extern void park( void ); 167 extern void unpark( struct $thread * this ); 168 168 static inline struct $thread * active_thread (); 169 169 … … 191 191 /* paranoid */ verify( expected == 0p ); 192 192 if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 193 park( __cfaabi_dbg_ctx);193 park(); 194 194 return true; 195 195 } … … 210 210 else { 211 211 if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 212 unpark( expected __cfaabi_dbg_ctx2);212 unpark( expected ); 213 213 return true; 214 214 } … … 244 244 /* paranoid */ verify( expected == 0p ); 245 245 if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 246 park( __cfaabi_dbg_ctx);246 park(); 247 247 /* paranoid */ verify( this.ptr == 1p ); 248 248 return true; … … 256 256 struct $thread * got = __atomic_exchange_n( &this.ptr, 1p, __ATOMIC_SEQ_CST); 257 257 if( got == 0p ) return false; 258 unpark( got __cfaabi_dbg_ctx2);258 unpark( got ); 259 259 return true; 260 260 } -
libcfa/src/concurrency/alarm.cfa
r038110a re235429 130 130 131 131 register_self( &node ); 132 park( __cfaabi_dbg_ctx);132 park(); 133 133 134 134 /* paranoid */ verify( !node.set ); -
libcfa/src/concurrency/clib/cfathread.cfa
r038110a re235429 44 44 45 45 void cfathread_park( void ) { 46 park( __cfaabi_dbg_ctx);46 park(); 47 47 } 48 48 49 49 void cfathread_unpark( CRunner * thrd ) { 50 unpark( *thrd __cfaabi_dbg_ctx2);50 unpark( *thrd ); 51 51 } 52 52 -
libcfa/src/concurrency/invoke.h
r038110a re235429 94 94 }; 95 95 // Wrapper for gdb 96 struct cfathread_coroutine_t { $coroutine debug; };96 struct cfathread_coroutine_t { struct $coroutine debug; }; 97 97 98 98 static inline struct __stack_t * __get_stack( struct $coroutine * cor ) { … … 132 132 }; 133 133 // Wrapper for gdb 134 struct cfathread_monitor_t { $monitor debug; };134 struct cfathread_monitor_t { struct $monitor debug; }; 135 135 136 136 struct __monitor_group_t { … … 191 191 192 192 #ifdef __CFA_DEBUG__ 193 // previous function to park/unpark the thread 194 const char * park_caller; 195 int park_result; 196 enum __Coroutine_State park_state; 197 bool park_stale; 198 const char * unpark_caller; 199 int unpark_result; 200 enum __Coroutine_State unpark_state; 201 bool unpark_stale; 193 unsigned long long canary; 202 194 #endif 203 195 }; 204 196 // Wrapper for gdb 205 struct cfathread_thread_t { $thread debug; };197 struct cfathread_thread_t { struct $thread debug; }; 206 198 207 199 #ifdef __CFA_DEBUG__ -
libcfa/src/concurrency/io.cfa
r038110a re235429 69 69 if( block ) { 70 70 enable_interrupts( __cfaabi_dbg_ctx ); 71 park( __cfaabi_dbg_ctx);71 park(); 72 72 disable_interrupts(); 73 73 } -
libcfa/src/concurrency/io/setup.cfa
r038110a re235429 247 247 thrd.link.next = 0p; 248 248 thrd.link.prev = 0p; 249 __cfaabi_dbg_debug_do( thrd.unpark_stale = true );250 249 251 250 // Fixup the thread state -
libcfa/src/concurrency/kernel.cfa
r038110a re235429 246 246 thrd_dst->state = Active; 247 247 248 __cfaabi_dbg_debug_do(249 thrd_dst->park_stale = true;250 thrd_dst->unpark_stale = true;251 )252 248 // Update global state 253 249 kernelTLS.this_thread = thrd_dst; … … 288 284 // The thread has halted, it should never be scheduled/run again 289 285 // We may need to wake someone up here since 290 unpark( this->destroyer __cfaabi_dbg_ctx2);286 unpark( this->destroyer ); 291 287 this->destroyer = 0p; 292 288 break RUNNING; … … 298 294 // set state of processor coroutine to active and the thread to inactive 299 295 int old_ticket = __atomic_fetch_sub(&thrd_dst->ticket, 1, __ATOMIC_SEQ_CST); 300 __cfaabi_dbg_debug_do( thrd_dst->park_result = old_ticket; )301 296 switch(old_ticket) { 302 297 case 1: … … 404 399 405 400 // KERNEL ONLY unpark with out disabling interrupts 406 void __unpark( struct __processor_id_t * id, $thread * thrd __cfaabi_dbg_ctx_param2 ) { 407 // record activity 408 __cfaabi_dbg_record_thrd( *thrd, false, caller ); 409 401 void __unpark( struct __processor_id_t * id, $thread * thrd ) { 410 402 int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST); 411 __cfaabi_dbg_debug_do( thrd->unpark_result = old_ticket; thrd->unpark_state = thrd->state; )412 403 switch(old_ticket) { 413 404 case 1: … … 427 418 } 428 419 429 void unpark( $thread * thrd __cfaabi_dbg_ctx_param2) {420 void unpark( $thread * thrd ) { 430 421 if( !thrd ) return; 431 422 432 423 disable_interrupts(); 433 __unpark( (__processor_id_t*)kernelTLS.this_processor, thrd __cfaabi_dbg_ctx_fwd2);424 __unpark( (__processor_id_t*)kernelTLS.this_processor, thrd ); 434 425 enable_interrupts( __cfaabi_dbg_ctx ); 435 426 } 436 427 437 void park( __cfaabi_dbg_ctx_param) {428 void park( void ) { 438 429 /* paranoid */ verify( kernelTLS.preemption_state.enabled ); 439 430 disable_interrupts(); 440 431 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 441 432 /* paranoid */ verify( kernelTLS.this_thread->preempted == __NO_PREEMPTION ); 442 443 // record activity444 __cfaabi_dbg_record_thrd( *kernelTLS.this_thread, true, caller );445 433 446 434 returnToKernel(); … … 650 638 // atomically release spin lock and block 651 639 unlock( lock ); 652 park( __cfaabi_dbg_ctx);640 park(); 653 641 return true; 654 642 } … … 671 659 672 660 // make new owner 673 unpark( thrd __cfaabi_dbg_ctx2);661 unpark( thrd ); 674 662 675 663 return thrd != 0p; … … 682 670 count += diff; 683 671 for(release) { 684 unpark( pop_head( waiting ) __cfaabi_dbg_ctx2);672 unpark( pop_head( waiting ) ); 685 673 } 686 674 … … 698 686 this.prev_thrd = kernelTLS.this_thread; 699 687 } 700 701 void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]) {702 if(park) {703 this.park_caller = prev_name;704 this.park_stale = false;705 }706 else {707 this.unpark_caller = prev_name;708 this.unpark_stale = false;709 }710 }711 688 } 712 689 ) -
libcfa/src/concurrency/kernel/fwd.hfa
r038110a re235429 118 118 119 119 extern "Cforall" { 120 extern void park( __cfaabi_dbg_ctx_param);121 extern void unpark( struct $thread * this __cfaabi_dbg_ctx_param2);120 extern void park( void ); 121 extern void unpark( struct $thread * this ); 122 122 static inline struct $thread * active_thread () { return TL_GET( this_thread ); } 123 123 -
libcfa/src/concurrency/kernel_private.hfa
r038110a re235429 64 64 65 65 // KERNEL ONLY unpark with out disabling interrupts 66 void __unpark( struct __processor_id_t *, $thread * thrd __cfaabi_dbg_ctx_param2);66 void __unpark( struct __processor_id_t *, $thread * thrd ); 67 67 68 68 static inline bool __post(single_sem & this, struct __processor_id_t * id) { … … 77 77 else { 78 78 if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 79 __unpark( id, expected __cfaabi_dbg_ctx2);79 __unpark( id, expected ); 80 80 return true; 81 81 } -
libcfa/src/concurrency/monitor.cfa
r038110a re235429 122 122 123 123 unlock( this->lock ); 124 park( __cfaabi_dbg_ctx);124 park(); 125 125 126 126 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); … … 201 201 // Release the next thread 202 202 /* paranoid */ verifyf( urgent->owner->waiting_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this ); 203 unpark( urgent->owner->waiting_thread __cfaabi_dbg_ctx2);203 unpark( urgent->owner->waiting_thread ); 204 204 205 205 // Park current thread waiting 206 park( __cfaabi_dbg_ctx);206 park(); 207 207 208 208 // Some one was waiting for us, enter … … 222 222 223 223 // Park current thread waiting 224 park( __cfaabi_dbg_ctx);224 park(); 225 225 226 226 /* paranoid */ verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this ); … … 264 264 //We need to wake-up the thread 265 265 /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this ); 266 unpark( new_owner __cfaabi_dbg_ctx2);266 unpark( new_owner ); 267 267 } 268 268 … … 493 493 // Wake the threads 494 494 for(int i = 0; i < thread_count; i++) { 495 unpark( threads[i] __cfaabi_dbg_ctx2);495 unpark( threads[i] ); 496 496 } 497 497 498 498 // Everything is ready to go to sleep 499 park( __cfaabi_dbg_ctx);499 park(); 500 500 501 501 // We are back, restore the owners and recursions … … 575 575 576 576 // unpark the thread we signalled 577 unpark( signallee __cfaabi_dbg_ctx2);577 unpark( signallee ); 578 578 579 579 //Everything is ready to go to sleep 580 park( __cfaabi_dbg_ctx);580 park(); 581 581 582 582 … … 679 679 680 680 // unpark the thread we signalled 681 unpark( next __cfaabi_dbg_ctx2);681 unpark( next ); 682 682 683 683 //Everything is ready to go to sleep 684 park( __cfaabi_dbg_ctx);684 park(); 685 685 686 686 // We are back, restore the owners and recursions … … 724 724 725 725 //Everything is ready to go to sleep 726 park( __cfaabi_dbg_ctx);726 park(); 727 727 728 728 -
libcfa/src/concurrency/mutex.cfa
r038110a re235429 42 42 append( blocked_threads, kernelTLS.this_thread ); 43 43 unlock( lock ); 44 park( __cfaabi_dbg_ctx);44 park(); 45 45 } 46 46 else { … … 65 65 this.is_locked = (this.blocked_threads != 0); 66 66 unpark( 67 pop_head( this.blocked_threads ) __cfaabi_dbg_ctx267 pop_head( this.blocked_threads ) 68 68 ); 69 69 unlock( this.lock ); … … 97 97 append( blocked_threads, kernelTLS.this_thread ); 98 98 unlock( lock ); 99 park( __cfaabi_dbg_ctx);99 park(); 100 100 } 101 101 } … … 124 124 owner = thrd; 125 125 recursion_count = (thrd ? 1 : 0); 126 unpark( thrd __cfaabi_dbg_ctx2);126 unpark( thrd ); 127 127 } 128 128 unlock( lock ); … … 142 142 lock( lock __cfaabi_dbg_ctx2 ); 143 143 unpark( 144 pop_head( this.blocked_threads ) __cfaabi_dbg_ctx2144 pop_head( this.blocked_threads ) 145 145 ); 146 146 unlock( lock ); … … 151 151 while(this.blocked_threads) { 152 152 unpark( 153 pop_head( this.blocked_threads ) __cfaabi_dbg_ctx2153 pop_head( this.blocked_threads ) 154 154 ); 155 155 } … … 161 161 append( this.blocked_threads, kernelTLS.this_thread ); 162 162 unlock( this.lock ); 163 park( __cfaabi_dbg_ctx);163 park(); 164 164 } 165 165 … … 170 170 unlock(l); 171 171 unlock(this.lock); 172 park( __cfaabi_dbg_ctx);172 park(); 173 173 lock(l); 174 174 } -
libcfa/src/concurrency/preemption.cfa
r038110a re235429 274 274 kernelTLS.this_stats = this->curr_cluster->stats; 275 275 #endif 276 __unpark( id, this __cfaabi_dbg_ctx2);276 __unpark( id, this ); 277 277 } 278 278 -
libcfa/src/concurrency/thread.hfa
r038110a re235429 88 88 //---------- 89 89 // Park thread: block until corresponding call to unpark, won't block if unpark is already called 90 void park( __cfaabi_dbg_ctx_param);90 void park( void ); 91 91 92 92 //---------- 93 93 // Unpark a thread, if the thread is already blocked, schedule it 94 94 // if the thread is not yet block, signal that it should rerun immediately 95 void unpark( $thread * this __cfaabi_dbg_ctx_param2);95 void unpark( $thread * this ); 96 96 97 97 forall( dtype T | is_thread(T) ) 98 static inline void unpark( T & this __cfaabi_dbg_ctx_param2 ) { if(!&this) return; unpark( get_thread( this ) __cfaabi_dbg_ctx_fwd2);}98 static inline void unpark( T & this ) { if(!&this) return; unpark( get_thread( this ) );} 99 99 100 100 //----------
Note: See TracChangeset
for help on using the changeset viewer.