Changeset e84ab3d for libcfa/src/concurrency/kernel.cfa
- Timestamp:
- Jul 5, 2021, 4:44:20 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7f62b708
- Parents:
- ee23a8d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
ree23a8d re84ab3d 110 110 #endif 111 111 112 extern $thread* mainThread;112 extern thread$ * mainThread; 113 113 extern processor * mainProcessor; 114 114 115 115 //----------------------------------------------------------------------------- 116 116 // Kernel Scheduling logic 117 static $thread* __next_thread(cluster * this);118 static $thread* __next_thread_slow(cluster * this);119 static inline bool __must_unpark( $thread* thrd ) __attribute((nonnull(1)));120 static void __run_thread(processor * this, $thread* dst);117 static thread$ * __next_thread(cluster * this); 118 static thread$ * __next_thread_slow(cluster * this); 119 static inline bool __must_unpark( thread$ * thrd ) __attribute((nonnull(1))); 120 static void __run_thread(processor * this, thread$ * dst); 121 121 static void __wake_one(cluster * cltr); 122 122 … … 181 181 __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this); 182 182 183 $thread* readyThread = 0p;183 thread$ * readyThread = 0p; 184 184 MAIN_LOOP: 185 185 for() { … … 388 388 // runThread runs a thread by context switching 389 389 // from the processor coroutine to the target thread 390 static void __run_thread(processor * this, $thread* thrd_dst) {390 static void __run_thread(processor * this, thread$ * thrd_dst) { 391 391 /* paranoid */ verify( ! __preemption_enabled() ); 392 392 /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted); … … 396 396 __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name); 397 397 398 $coroutine* proc_cor = get_coroutine(this->runner);398 coroutine$ * proc_cor = get_coroutine(this->runner); 399 399 400 400 // set state of processor coroutine to inactive … … 415 415 /* paranoid */ verify( thrd_dst->context.SP ); 416 416 /* paranoid */ verify( thrd_dst->state != Halted ); 417 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination $thread%p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor418 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination $thread%p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor417 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor 418 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor 419 419 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary ); 420 420 … … 428 428 429 429 /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary ); 430 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination $thread%p has been corrupted.\n StackPointer too large.\n", thrd_dst );431 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination $thread%p has been corrupted.\n StackPointer too small.\n", thrd_dst );430 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); 431 /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); 432 432 /* paranoid */ verify( thrd_dst->context.SP ); 433 433 /* paranoid */ verify( thrd_dst->curr_cluster == this->cltr ); … … 497 497 void returnToKernel() { 498 498 /* paranoid */ verify( ! __preemption_enabled() ); 499 $coroutine* proc_cor = get_coroutine(kernelTLS().this_processor->runner);500 $thread* thrd_src = kernelTLS().this_thread;499 coroutine$ * proc_cor = get_coroutine(kernelTLS().this_processor->runner); 500 thread$ * thrd_src = kernelTLS().this_thread; 501 501 502 502 __STATS( thrd_src->last_proc = kernelTLS().this_processor; ) … … 526 526 527 527 /* paranoid */ verify( ! __preemption_enabled() ); 528 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning $thread%p has been corrupted.\n StackPointer too small.\n", thrd_src );529 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning $thread%p has been corrupted.\n StackPointer too large.\n", thrd_src );528 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) < ((uintptr_t)__get_stack(thrd_src->curr_cor)->base ) || thrd_src->corctx_flag, "ERROR : Returning thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_src ); 529 /* paranoid */ verifyf( ((uintptr_t)thrd_src->context.SP) > ((uintptr_t)__get_stack(thrd_src->curr_cor)->limit) || thrd_src->corctx_flag, "ERROR : Returning thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_src ); 530 530 } 531 531 … … 533 533 // Scheduler routines 534 534 // KERNEL ONLY 535 static void __schedule_thread( $thread* thrd ) {535 static void __schedule_thread( thread$ * thrd ) { 536 536 /* paranoid */ verify( ! __preemption_enabled() ); 537 537 /* paranoid */ verify( ready_schedule_islocked()); … … 583 583 } 584 584 585 void schedule_thread$( $thread* thrd ) {585 void schedule_thread$( thread$ * thrd ) { 586 586 ready_schedule_lock(); 587 587 __schedule_thread( thrd ); … … 590 590 591 591 // KERNEL ONLY 592 static inline $thread* __next_thread(cluster * this) with( *this ) {592 static inline thread$ * __next_thread(cluster * this) with( *this ) { 593 593 /* paranoid */ verify( ! __preemption_enabled() ); 594 594 595 595 ready_schedule_lock(); 596 $thread* thrd = pop_fast( this );596 thread$ * thrd = pop_fast( this ); 597 597 ready_schedule_unlock(); 598 598 … … 602 602 603 603 // KERNEL ONLY 604 static inline $thread* __next_thread_slow(cluster * this) with( *this ) {604 static inline thread$ * __next_thread_slow(cluster * this) with( *this ) { 605 605 /* paranoid */ verify( ! __preemption_enabled() ); 606 606 607 607 ready_schedule_lock(); 608 $thread* thrd;608 thread$ * thrd; 609 609 for(25) { 610 610 thrd = pop_slow( this ); … … 620 620 } 621 621 622 static inline bool __must_unpark( $thread* thrd ) {622 static inline bool __must_unpark( thread$ * thrd ) { 623 623 int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST); 624 624 switch(old_ticket) { … … 636 636 } 637 637 638 void __kernel_unpark( $thread* thrd ) {638 void __kernel_unpark( thread$ * thrd ) { 639 639 /* paranoid */ verify( ! __preemption_enabled() ); 640 640 /* paranoid */ verify( ready_schedule_islocked()); … … 651 651 } 652 652 653 void unpark( $thread* thrd ) {653 void unpark( thread$ * thrd ) { 654 654 if( !thrd ) return; 655 655 … … 675 675 // Should never return 676 676 void __cfactx_thrd_leave() { 677 $thread* thrd = active_thread();678 $monitor* this = &thrd->self_mon;677 thread$ * thrd = active_thread(); 678 monitor$ * this = &thrd->self_mon; 679 679 680 680 // Lock the monitor now … … 688 688 /* paranoid */ verify( kernelTLS().this_thread == thrd ); 689 689 /* paranoid */ verify( thrd->context.SP ); 690 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) > ((uintptr_t)__get_stack(thrd->curr_cor)->limit), "ERROR : $thread%p has been corrupted.\n StackPointer too large.\n", thrd );691 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : $thread%p has been corrupted.\n StackPointer too small.\n", thrd );690 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) > ((uintptr_t)__get_stack(thrd->curr_cor)->limit), "ERROR : thread$ %p has been corrupted.\n StackPointer too large.\n", thrd ); 691 /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : thread$ %p has been corrupted.\n StackPointer too small.\n", thrd ); 692 692 693 693 thrd->state = Halting; … … 707 707 bool force_yield( __Preemption_Reason reason ) { 708 708 __disable_interrupts_checked(); 709 $thread* thrd = kernelTLS().this_thread;709 thread$ * thrd = kernelTLS().this_thread; 710 710 /* paranoid */ verify(thrd->state == Active); 711 711 … … 819 819 //============================================================================================= 820 820 void __kernel_abort_msg( char * abort_text, int abort_text_size ) { 821 $thread* thrd = __cfaabi_tls.this_thread;821 thread$ * thrd = __cfaabi_tls.this_thread; 822 822 823 823 if(thrd) {
Note: See TracChangeset
for help on using the changeset viewer.