- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.cfa (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r6a77224 rb4b63e8 252 252 /* paranoid */ verify( kernelTLS.this_thread == thrd_dst ); 253 253 /* paranoid */ verify( thrd_dst->context.SP ); 254 /* paranoid */ verify( thrd_dst->state != Halted );255 254 /* 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 256 255 /* 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 … … 288 287 if(unlikely(thrd_dst->state == Halted)) { 289 288 // The thread has halted, it should never be scheduled/run again 290 // finish the thread 291 __thread_finish( thrd_dst ); 289 // We may need to wake someone up here since 290 unpark( this->destroyer ); 291 this->destroyer = 0p; 292 292 break RUNNING; 293 293 } … … 299 299 int old_ticket = __atomic_fetch_sub(&thrd_dst->ticket, 1, __ATOMIC_SEQ_CST); 300 300 switch(old_ticket) { 301 case TICKET_RUNNING:301 case 1: 302 302 // This is case 1, the regular case, nothing more is needed 303 303 break RUNNING; 304 case TICKET_UNBLOCK:304 case 2: 305 305 // This is case 2, the racy case, someone tried to run this thread before it finished blocking 306 306 // In this case, just run it again. … … 410 410 int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST); 411 411 switch(old_ticket) { 412 case TICKET_RUNNING:412 case 1: 413 413 // Wake won the race, the thread will reschedule/rerun itself 414 414 break; 415 case TICKET_BLOCKED:415 case 0: 416 416 /* paranoid */ verify( ! thrd->preempted != __NO_PREEMPTION ); 417 417 /* paranoid */ verify( thrd->state == Blocked ); … … 422 422 default: 423 423 // This makes no sense, something is wrong abort 424 abort( "Thread %p (%s) has mismatch park/unpark\n", thrd, thrd->self_cor.name);424 abort(); 425 425 } 426 426 } … … 448 448 } 449 449 450 extern "C" { 451 // Leave the thread monitor 452 // last routine called by a thread. 453 // Should never return 454 void __cfactx_thrd_leave() { 455 $thread * thrd = TL_GET( this_thread ); 456 $monitor * this = &thrd->self_mon; 457 458 // Lock the monitor now 459 lock( this->lock __cfaabi_dbg_ctx2 ); 460 461 disable_interrupts(); 462 463 thrd->state = Halted; 464 465 if( thrd != this->owner || this->recursion != 1) { abort( "Thread internal monitor has unbalanced recursion" ); } 466 467 // Leave the thread 468 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 469 returnToKernel(); 470 abort(); 471 472 // Control flow should never reach here! 473 } 450 // KERNEL ONLY 451 void __leave_thread() { 452 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled ); 453 returnToKernel(); 454 abort(); 474 455 } 475 456
Note:
See TracChangeset
for help on using the changeset viewer.