Changeset 2e9aed4
- Timestamp:
- Jan 30, 2018, 2:04:27 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- ffd0ac2
- Parents:
- 813ddcaa
- Location:
- src/libcfa
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/libcfa/bits/locks.h ¶
r813ddcaa r2e9aed4 65 65 extern void yield( unsigned int ); 66 66 extern thread_local struct thread_desc * volatile this_thread; 67 extern thread_local struct processor * volatile this_processor; 67 68 68 69 static inline void ?{}( __spinlock_t & this ) { … … 112 113 } 113 114 114 // Lock the spinlock, spinif already acquired115 static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {116 for ( unsigned int i = 1;; i += 1 ) {117 if ( __lock_test_and_test_and_set( this.lock ) ) break;118 yield( i );119 }120 disable_interrupts();121 __cfaabi_dbg_debug_do(122 this.prev_name = caller;123 this.prev_thrd = this_thread;124 )125 }115 // // Lock the spinlock, yield if already acquired 116 // static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 117 // for ( unsigned int i = 1;; i += 1 ) { 118 // if ( __lock_test_and_test_and_set( this.lock ) ) break; 119 // yield( i ); 120 // } 121 // disable_interrupts(); 122 // __cfaabi_dbg_debug_do( 123 // this.prev_name = caller; 124 // this.prev_thrd = this_thread; 125 // ) 126 // } 126 127 127 128 static inline void unlock( __spinlock_t & this ) { 129 enable_interrupts_noPoll(); 128 130 __lock_release( this.lock ); 129 enable_interrupts_noPoll();130 131 } 131 132 #endif -
TabularUnified src/libcfa/concurrency/kernel.c ¶
r813ddcaa r2e9aed4 242 242 void finishRunning(processor * this) { 243 243 if( this->finish.action_code == Release ) { 244 verify( disable_preempt_count > 1 ); 244 245 unlock( *this->finish.lock ); 245 246 } … … 248 249 } 249 250 else if( this->finish.action_code == Release_Schedule ) { 251 verify( disable_preempt_count > 1 ); 250 252 unlock( *this->finish.lock ); 251 253 ScheduleThread( this->finish.thrd ); 252 254 } 253 255 else if( this->finish.action_code == Release_Multi ) { 256 verify( disable_preempt_count > this->finish.lock_count ); 254 257 for(int i = 0; i < this->finish.lock_count; i++) { 255 258 unlock( *this->finish.locks[i] ); … … 257 260 } 258 261 else if( this->finish.action_code == Release_Multi_Schedule ) { 262 verify( disable_preempt_count > this->finish.lock_count ); 259 263 for(int i = 0; i < this->finish.lock_count; i++) { 260 264 unlock( *this->finish.locks[i] ); … … 363 367 this_processor->finish.lock = lock; 364 368 365 verify( disable_preempt_count > 0);369 verify( disable_preempt_count > 1 ); 366 370 suspend(); 367 371 verify( disable_preempt_count > 0 ); … … 391 395 this_processor->finish.thrd = thrd; 392 396 393 verify( disable_preempt_count > 0);397 verify( disable_preempt_count > 1 ); 394 398 suspend(); 395 399 verify( disable_preempt_count > 0 ); -
TabularUnified src/libcfa/concurrency/monitor.c ¶
r813ddcaa r2e9aed4 53 53 static inline __lock_size_t aggregate ( monitor_desc * storage [], const __waitfor_mask_t & mask ); 54 54 55 #ifndef __CFA_LOCK_NO_YIELD56 #define DO_LOCK lock_yield57 #else58 #define DO_LOCK lock59 #endif60 61 55 //----------------------------------------------------------------------------- 62 56 // Useful defines … … 90 84 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 91 85 // Lock the monitor spinlock 92 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );86 lock( this->lock __cfaabi_dbg_ctx2 ); 93 87 thread_desc * thrd = this_thread; 88 89 verify( disable_preempt_count > 0 ); 94 90 95 91 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); … … 121 117 // Some one else has the monitor, wait in line for it 122 118 append( this->entry_queue, thrd ); 119 120 verify( disable_preempt_count > 0 ); 121 123 122 BlockInternal( &this->lock ); 124 123 … … 138 137 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 139 138 // Lock the monitor spinlock 140 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );139 lock( this->lock __cfaabi_dbg_ctx2 ); 141 140 thread_desc * thrd = this_thread; 142 141 … … 201 200 // Leave single monitor 202 201 void __leave_monitor_desc( monitor_desc * this ) { 203 // Lock the monitor spinlock , DO_LOCK to reduce contention204 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );202 // Lock the monitor spinlock 203 lock( this->lock __cfaabi_dbg_ctx2 ); 205 204 206 205 __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); … … 248 247 249 248 // Lock the monitor now 250 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );249 lock( this->lock __cfaabi_dbg_ctx2 ); 251 250 252 251 disable_interrupts(); … … 397 396 append( this.blocked, &waiter ); 398 397 398 verify( disable_preempt_count == 0 ); 399 399 400 // Lock all monitors (aggregates the locks as well) 400 401 lock_all( monitors, locks, count ); 402 403 // verifyf( disable_preempt_count == count, "Got %d, expected %d\n", disable_preempt_count, count ); 404 if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); } 401 405 402 406 // Find the next thread(s) to run … … 473 477 monitor_ctx( this.monitors, this.monitor_count ); 474 478 479 verify( disable_preempt_count == 0 ); 480 475 481 // Lock all monitors (aggregates the locks them as well) 476 482 lock_all( monitors, locks, count ); 483 484 // verify( disable_preempt_count == count ); 485 if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); } 486 477 487 478 488 // Create the node specific to this wait operation … … 737 747 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) { 738 748 for( __lock_size_t i = 0; i < count; i++ ) { 739 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );749 lock( *locks[i] __cfaabi_dbg_ctx2 ); 740 750 } 741 751 } … … 744 754 for( __lock_size_t i = 0; i < count; i++ ) { 745 755 __spinlock_t * l = &source[i]->lock; 746 DO_LOCK( *l __cfaabi_dbg_ctx2 );756 lock( *l __cfaabi_dbg_ctx2 ); 747 757 if(locks) locks[i] = l; 748 758 } -
TabularUnified src/libcfa/concurrency/preemption.c ¶
r813ddcaa r2e9aed4 169 169 void enable_interrupts_noPoll() { 170 170 __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST ); 171 verify ( prev != 0u); // If this triggers someone is enabled already enabled interrupts171 verifyf( prev != 0u, "Incremented from %u\n", prev ); // If this triggers someone is enabled already enabled interrupts 172 172 } 173 173 } … … 293 293 if( !preemption_ready() ) { return; } 294 294 295 //__cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);295 __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread); 296 296 297 297 preemption_in_progress = true; // Sync flag : prevent recursive calls to the signal handler
Note: See TracChangeset
for help on using the changeset viewer.