Changeset ae66348
- Timestamp:
- Mar 24, 2020, 1:39:31 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c72ea7a, f100a83
- Parents:
- 210b8b3
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/debug.hfa
r210b8b3 rae66348 23 23 #define __cfaabi_dbg_ctx_param const char caller[] 24 24 #define __cfaabi_dbg_ctx_param2 , const char caller[] 25 #define __cfaabi_dbg_ctx_fwd caller 26 #define __cfaabi_dbg_ctx_fwd2 , caller 25 27 #else 26 28 #define __cfaabi_dbg_debug_do(...) … … 30 32 #define __cfaabi_dbg_ctx_param 31 33 #define __cfaabi_dbg_ctx_param2 34 #define __cfaabi_dbg_ctx_fwd 35 #define __cfaabi_dbg_ctx_fwd2 32 36 #endif 33 37 -
libcfa/src/bits/locks.hfa
r210b8b3 rae66348 54 54 55 55 #ifdef __CFA_DEBUG__ 56 void __cfaabi_dbg_record (__spinlock_t & this, const char prev_name[]);56 void __cfaabi_dbg_record_lock(__spinlock_t & this, const char prev_name[]); 57 57 #else 58 #define __cfaabi_dbg_record (x, y)58 #define __cfaabi_dbg_record_lock(x, y) 59 59 #endif 60 60 } … … 69 69 bool result = (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0); 70 70 if( result ) { 71 __cfaabi_dbg_record ( this, caller );71 __cfaabi_dbg_record_lock( this, caller ); 72 72 } else { 73 73 enable_interrupts_noPoll(); … … 99 99 #endif 100 100 } 101 __cfaabi_dbg_record ( this, caller );101 __cfaabi_dbg_record_lock( this, caller ); 102 102 } 103 103 -
libcfa/src/concurrency/invoke.h
r210b8b3 rae66348 198 198 struct $thread * prev; 199 199 } node; 200 }; 200 201 #ifdef __CFA_DEBUG__ 202 // previous function to park/unpark the thread 203 const char * prev_park; 204 bool park_stale; 205 const char * prev_unpark; 206 bool unpark_stale; 207 #endif 208 }; 209 210 #ifdef __CFA_DEBUG__ 211 void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]); 212 #else 213 #define __cfaabi_dbg_record_thrd(x, y, z) 214 #endif 201 215 202 216 #ifdef __cforall -
libcfa/src/concurrency/kernel.cfa
r210b8b3 rae66348 343 343 } 344 344 345 __cfaabi_dbg_debug_do( 346 thrd_dst->park_stale = true; 347 thrd_dst->park_stale = false; 348 ) 349 345 350 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 346 351 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor … … 381 386 382 387 // We may need to wake someone up here since 383 unpark( this->destroyer );388 unpark( this->destroyer __cfaabi_dbg_ctx2 ); 384 389 this->destroyer = 0p; 385 390 break RUNNING; … … 588 593 } 589 594 590 void unpark( $thread * thrd ) {595 void unpark( $thread * thrd __cfaabi_dbg_ctx_param2 ) { 591 596 if( !thrd ) return; 592 597 593 598 disable_interrupts(); 594 599 static_assert(sizeof(thrd->state) == sizeof(int)); 600 601 // record activity 602 __cfaabi_dbg_record_thrd( *thrd, false, caller ); 603 595 604 enum coroutine_state old_state = __atomic_exchange_n(&thrd->state, Rerun, __ATOMIC_SEQ_CST); 596 605 switch(old_state) { … … 618 627 } 619 628 620 void park( void) {629 void park( __cfaabi_dbg_ctx_param ) { 621 630 /* paranoid */ verify( kernelTLS.preemption_state.enabled ); 622 631 disable_interrupts(); 623 632 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 624 633 /* paranoid */ verify( kernelTLS.this_thread->preempted == __NO_PREEMPTION ); 634 635 // record activity 636 __cfaabi_dbg_record_thrd( *kernelTLS.this_thread, true, caller ); 625 637 626 638 returnToKernel(); … … 898 910 // atomically release spin lock and block 899 911 unlock( lock ); 900 park( );912 park( __cfaabi_dbg_ctx ); 901 913 } 902 914 else { … … 917 929 918 930 // make new owner 919 unpark( thrd );931 unpark( thrd __cfaabi_dbg_ctx2 ); 920 932 } 921 933 … … 966 978 __cfaabi_dbg_debug_do( 967 979 extern "C" { 968 void __cfaabi_dbg_record (__spinlock_t & this, const char prev_name[]) {980 void __cfaabi_dbg_record_lock(__spinlock_t & this, const char prev_name[]) { 969 981 this.prev_name = prev_name; 970 982 this.prev_thrd = kernelTLS.this_thread; 983 } 984 985 void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]) { 986 if(park) { 987 this.prev_park = prev_name; 988 this.park_stale = false; 989 } 990 else { 991 this.prev_unpark = prev_name; 992 this.unpark_stale = false; 993 } 971 994 } 972 995 } -
libcfa/src/concurrency/monitor.cfa
r210b8b3 rae66348 119 119 120 120 unlock( this->lock ); 121 park( );121 park( __cfaabi_dbg_ctx ); 122 122 123 123 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this); … … 184 184 // Release the next thread 185 185 /* 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 ); 186 unpark( urgent->owner->waiting_thread );186 unpark( urgent->owner->waiting_thread __cfaabi_dbg_ctx2 ); 187 187 188 188 // Park current thread waiting 189 park( );189 park( __cfaabi_dbg_ctx ); 190 190 191 191 // Some one was waiting for us, enter … … 205 205 206 206 // Park current thread waiting 207 park( );207 park( __cfaabi_dbg_ctx ); 208 208 209 209 /* 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 ); … … 247 247 //We need to wake-up the thread 248 248 /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this ); 249 unpark( new_owner );249 unpark( new_owner __cfaabi_dbg_ctx2 ); 250 250 } 251 251 … … 460 460 // Wake the threads 461 461 for(int i = 0; i < thread_count; i++) { 462 unpark( threads[i] );462 unpark( threads[i] __cfaabi_dbg_ctx2 ); 463 463 } 464 464 465 465 // Everything is ready to go to sleep 466 park( );466 park( __cfaabi_dbg_ctx ); 467 467 468 468 // We are back, restore the owners and recursions … … 542 542 543 543 // unpark the thread we signalled 544 unpark( signallee );544 unpark( signallee __cfaabi_dbg_ctx2 ); 545 545 546 546 //Everything is ready to go to sleep 547 park( );547 park( __cfaabi_dbg_ctx ); 548 548 549 549 … … 646 646 647 647 // unpark the thread we signalled 648 unpark( next );648 unpark( next __cfaabi_dbg_ctx2 ); 649 649 650 650 //Everything is ready to go to sleep 651 park( );651 park( __cfaabi_dbg_ctx ); 652 652 653 653 // We are back, restore the owners and recursions … … 691 691 692 692 //Everything is ready to go to sleep 693 park( );693 park( __cfaabi_dbg_ctx ); 694 694 695 695 -
libcfa/src/concurrency/mutex.cfa
r210b8b3 rae66348 41 41 append( blocked_threads, kernelTLS.this_thread ); 42 42 unlock( lock ); 43 park( );43 park( __cfaabi_dbg_ctx ); 44 44 } 45 45 else { … … 64 64 this.is_locked = (this.blocked_threads != 0); 65 65 unpark( 66 pop_head( this.blocked_threads ) 66 pop_head( this.blocked_threads ) __cfaabi_dbg_ctx2 67 67 ); 68 68 unlock( this.lock ); … … 96 96 append( blocked_threads, kernelTLS.this_thread ); 97 97 unlock( lock ); 98 park( );98 park( __cfaabi_dbg_ctx ); 99 99 } 100 100 } … … 123 123 owner = thrd; 124 124 recursion_count = (thrd ? 1 : 0); 125 unpark( thrd );125 unpark( thrd __cfaabi_dbg_ctx2 ); 126 126 } 127 127 unlock( lock ); … … 141 141 lock( lock __cfaabi_dbg_ctx2 ); 142 142 unpark( 143 pop_head( this.blocked_threads ) 143 pop_head( this.blocked_threads ) __cfaabi_dbg_ctx2 144 144 ); 145 145 unlock( lock ); … … 150 150 while(this.blocked_threads) { 151 151 unpark( 152 pop_head( this.blocked_threads ) 152 pop_head( this.blocked_threads ) __cfaabi_dbg_ctx2 153 153 ); 154 154 } … … 160 160 append( this.blocked_threads, kernelTLS.this_thread ); 161 161 unlock( this.lock ); 162 park( );162 park( __cfaabi_dbg_ctx ); 163 163 } 164 164 … … 169 169 unlock(l); 170 170 unlock(this.lock); 171 park( );171 park( __cfaabi_dbg_ctx ); 172 172 lock(l); 173 173 } -
libcfa/src/concurrency/thread.hfa
r210b8b3 rae66348 92 92 //---------- 93 93 // Park thread: block until corresponding call to unpark, won't block if unpark is already called 94 void park( void);94 void park( __cfaabi_dbg_ctx_param ); 95 95 96 96 //---------- 97 97 // Unpark a thread, if the thread is already blocked, schedule it 98 98 // if the thread is not yet block, signal that it should rerun immediately 99 void unpark( $thread * this );99 void unpark( $thread * this __cfaabi_dbg_ctx_param2 ); 100 100 101 101 forall( dtype T | is_thread(T) ) 102 static inline void unpark( T & this ) { if(!&this) return; unpark( get_thread( this ));}102 static inline void unpark( T & this __cfaabi_dbg_ctx_param2 ) { if(!&this) return; unpark( get_thread( this ) __cfaabi_dbg_ctx_fwd2 );} 103 103 104 104 //---------- -
libcfa/src/startup.cfa
r210b8b3 rae66348 41 41 struct __spinlock_t; 42 42 extern "C" { 43 void __cfaabi_dbg_record (struct __spinlock_t & this, const char prev_name[]) __attribute__(( weak )) {}43 void __cfaabi_dbg_record_lock(struct __spinlock_t & this, const char prev_name[]) __attribute__(( weak )) {} 44 44 } 45 45 -
tests/concurrent/park/contention.cfa
r210b8b3 rae66348 21 21 if(blocked[idx]) { 22 22 Thread * thrd = __atomic_exchange_n(&blocked[idx], 0p, __ATOMIC_SEQ_CST); 23 unpark( *thrd );23 unpark( *thrd __cfaabi_dbg_ctx2 ); 24 24 } else { 25 25 Thread * thrd = __atomic_exchange_n(&blocked[idx], &this, __ATOMIC_SEQ_CST); 26 unpark( *thrd );27 park( );26 unpark( *thrd __cfaabi_dbg_ctx2 ); 27 park( __cfaabi_dbg_ctx ); 28 28 } 29 29 } … … 41 41 int idx = myrand() % blocked_size; 42 42 Thread * thrd = __atomic_exchange_n(&blocked[idx], 0p, __ATOMIC_SEQ_CST); 43 unpark( *thrd );43 unpark( *thrd __cfaabi_dbg_ctx2 ); 44 44 yield( myrand() % 20 ); 45 45 } -
tests/concurrent/park/force_preempt.cfa
r210b8b3 rae66348 30 30 31 31 // Unpark this thread, don't force a yield 32 unpark( this);32 unpark( this __cfaabi_dbg_ctx2 ); 33 33 assert(mask == 0xCAFEBABA); 34 34 … … 43 43 // Park this thread, 44 44 assert(mask == (id_hash ^ 0xCAFEBABA)); 45 park( );45 park( __cfaabi_dbg_ctx ); 46 46 assert(mask == (id_hash ^ 0xCAFEBABA)); 47 47
Note: See TracChangeset
for help on using the changeset viewer.