- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
rb4b63e8 r0190480 237 237 $coroutine * proc_cor = get_coroutine(this->runner); 238 238 239 // Update global state 240 kernelTLS.this_thread = thrd_dst; 241 239 242 // set state of processor coroutine to inactive 240 243 verify(proc_cor->state == Active); … … 246 249 thrd_dst->state = Active; 247 250 248 // Update global state 249 kernelTLS.this_thread = thrd_dst; 251 __cfaabi_dbg_debug_do( 252 thrd_dst->park_stale = true; 253 thrd_dst->unpark_stale = true; 254 ) 250 255 251 256 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 252 257 /* paranoid */ verify( kernelTLS.this_thread == thrd_dst ); 253 /* paranoid */ verify( thrd_dst->context.SP );254 258 /* 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 255 259 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor 256 /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd_dst->canary );257 258 259 260 260 261 // set context switch to the thread that the processor is executing 262 verify( thrd_dst->context.SP ); 261 263 __cfactx_switch( &proc_cor->context, &thrd_dst->context ); 262 264 // when __cfactx_switch returns we are back in the processor coroutine 263 265 264 /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd_dst->canary );265 266 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit), "ERROR : Destination $thread %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); 266 267 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ), "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); 267 /* paranoid */ verify( thrd_dst->context.SP );268 268 /* paranoid */ verify( kernelTLS.this_thread == thrd_dst ); 269 269 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 270 270 271 // Reset global state272 kernelTLS.this_thread = 0p;273 271 274 272 // We just finished running a thread, there are a few things that could have happened. … … 288 286 // The thread has halted, it should never be scheduled/run again 289 287 // We may need to wake someone up here since 290 unpark( this->destroyer );288 unpark( this->destroyer __cfaabi_dbg_ctx2 ); 291 289 this->destroyer = 0p; 292 290 break RUNNING; … … 298 296 // set state of processor coroutine to active and the thread to inactive 299 297 int old_ticket = __atomic_fetch_sub(&thrd_dst->ticket, 1, __ATOMIC_SEQ_CST); 298 __cfaabi_dbg_debug_do( thrd_dst->park_result = old_ticket; ) 300 299 switch(old_ticket) { 301 300 case 1: … … 314 313 // Just before returning to the processor, set the processor coroutine to active 315 314 proc_cor->state = Active; 315 kernelTLS.this_thread = 0p; 316 316 317 317 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); … … 334 334 __x87_store; 335 335 #endif 336 /* paranoid */ verify( proc_cor->context.SP ); 337 /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd_src->canary ); 336 verify( proc_cor->context.SP ); 338 337 __cfactx_switch( &thrd_src->context, &proc_cor->context ); 339 /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd_src->canary );340 338 #if defined( __i386 ) || defined( __x86_64 ) 341 339 __x87_load; … … 369 367 /* paranoid */ #endif 370 368 /* paranoid */ verifyf( thrd->link.next == 0p, "Expected null got %p", thrd->link.next ); 371 /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd->canary );372 373 369 374 370 if (thrd->preempted == __NO_PREEMPTION) thrd->state = Ready; … … 407 403 408 404 // KERNEL ONLY unpark with out disabling interrupts 409 void __unpark( struct __processor_id_t * id, $thread * thrd ) { 405 void __unpark( struct __processor_id_t * id, $thread * thrd __cfaabi_dbg_ctx_param2 ) { 406 // record activity 407 __cfaabi_dbg_record_thrd( *thrd, false, caller ); 408 410 409 int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST); 410 __cfaabi_dbg_debug_do( thrd->unpark_result = old_ticket; thrd->unpark_state = thrd->state; ) 411 411 switch(old_ticket) { 412 412 case 1: … … 426 426 } 427 427 428 void unpark( $thread * thrd ) {428 void unpark( $thread * thrd __cfaabi_dbg_ctx_param2 ) { 429 429 if( !thrd ) return; 430 430 431 431 disable_interrupts(); 432 __unpark( (__processor_id_t*)kernelTLS.this_processor, thrd );432 __unpark( (__processor_id_t*)kernelTLS.this_processor, thrd __cfaabi_dbg_ctx_fwd2 ); 433 433 enable_interrupts( __cfaabi_dbg_ctx ); 434 434 } 435 435 436 void park( void) {436 void park( __cfaabi_dbg_ctx_param ) { 437 437 /* paranoid */ verify( kernelTLS.preemption_state.enabled ); 438 438 disable_interrupts(); 439 439 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 440 440 /* paranoid */ verify( kernelTLS.this_thread->preempted == __NO_PREEMPTION ); 441 442 // record activity 443 __cfaabi_dbg_record_thrd( *kernelTLS.this_thread, true, caller ); 441 444 442 445 returnToKernel(); … … 518 521 disable_interrupts(); 519 522 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 520 post( this->idle );523 bool ret = post( this->idle ); 521 524 enable_interrupts( __cfaabi_dbg_ctx ); 522 525 } … … 646 649 // atomically release spin lock and block 647 650 unlock( lock ); 648 park( );651 park( __cfaabi_dbg_ctx ); 649 652 return true; 650 653 } … … 667 670 668 671 // make new owner 669 unpark( thrd );672 unpark( thrd __cfaabi_dbg_ctx2 ); 670 673 671 674 return thrd != 0p; … … 678 681 count += diff; 679 682 for(release) { 680 unpark( pop_head( waiting ) );683 unpark( pop_head( waiting ) __cfaabi_dbg_ctx2 ); 681 684 } 682 685 … … 694 697 this.prev_thrd = kernelTLS.this_thread; 695 698 } 699 700 void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]) { 701 if(park) { 702 this.park_caller = prev_name; 703 this.park_stale = false; 704 } 705 else { 706 this.unpark_caller = prev_name; 707 this.unpark_stale = false; 708 } 709 } 696 710 } 697 711 )
Note: See TracChangeset
for help on using the changeset viewer.