Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel.cfa

    re84ab3d r12daa43  
    110110#endif
    111111
    112 extern thread$ * mainThread;
     112extern $thread * mainThread;
    113113extern processor * mainProcessor;
    114114
    115115//-----------------------------------------------------------------------------
    116116// 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);
     117static $thread * __next_thread(cluster * this);
     118static $thread * __next_thread_slow(cluster * this);
     119static inline bool __must_unpark( $thread * thrd ) __attribute((nonnull(1)));
     120static void __run_thread(processor * this, $thread * dst);
    121121static void __wake_one(cluster * cltr);
    122122
     
    181181                __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this);
    182182
    183                 thread$ * readyThread = 0p;
     183                $thread * readyThread = 0p;
    184184                MAIN_LOOP:
    185185                for() {
     
    388388// runThread runs a thread by context switching
    389389// from the processor coroutine to the target thread
    390 static void __run_thread(processor * this, thread$ * thrd_dst) {
     390static void __run_thread(processor * this, $thread * thrd_dst) {
    391391        /* paranoid */ verify( ! __preemption_enabled() );
    392392        /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted);
     
    396396        __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name);
    397397
    398         coroutine$ * proc_cor = get_coroutine(this->runner);
     398        $coroutine * proc_cor = get_coroutine(this->runner);
    399399
    400400        // set state of processor coroutine to inactive
     
    415415                /* paranoid */ verify( thrd_dst->context.SP );
    416416                /* 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 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
     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 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
    419419                /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary );
    420420
     
    428428
    429429                /* 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 );
    432432                /* paranoid */ verify( thrd_dst->context.SP );
    433433                /* paranoid */ verify( thrd_dst->curr_cluster == this->cltr );
     
    497497void returnToKernel() {
    498498        /* 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;
    501501
    502502        __STATS( thrd_src->last_proc = kernelTLS().this_processor; )
     
    526526
    527527        /* 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 );
    530530}
    531531
     
    533533// Scheduler routines
    534534// KERNEL ONLY
    535 static void __schedule_thread( thread$ * thrd ) {
     535static void __schedule_thread( $thread * thrd ) {
    536536        /* paranoid */ verify( ! __preemption_enabled() );
    537537        /* paranoid */ verify( ready_schedule_islocked());
     
    583583}
    584584
    585 void schedule_thread$( thread$ * thrd ) {
     585void schedule_thread$( $thread * thrd ) {
    586586        ready_schedule_lock();
    587587                __schedule_thread( thrd );
     
    590590
    591591// KERNEL ONLY
    592 static inline thread$ * __next_thread(cluster * this) with( *this ) {
     592static inline $thread * __next_thread(cluster * this) with( *this ) {
    593593        /* paranoid */ verify( ! __preemption_enabled() );
    594594
    595595        ready_schedule_lock();
    596                 thread$ * thrd = pop_fast( this );
     596                $thread * thrd = pop_fast( this );
    597597        ready_schedule_unlock();
    598598
     
    602602
    603603// KERNEL ONLY
    604 static inline thread$ * __next_thread_slow(cluster * this) with( *this ) {
     604static inline $thread * __next_thread_slow(cluster * this) with( *this ) {
    605605        /* paranoid */ verify( ! __preemption_enabled() );
    606606
    607607        ready_schedule_lock();
    608                 thread$ * thrd;
     608                $thread * thrd;
    609609                for(25) {
    610610                        thrd = pop_slow( this );
     
    620620}
    621621
    622 static inline bool __must_unpark( thread$ * thrd ) {
     622static inline bool __must_unpark( $thread * thrd ) {
    623623        int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST);
    624624        switch(old_ticket) {
     
    636636}
    637637
    638 void __kernel_unpark( thread$ * thrd ) {
     638void __kernel_unpark( $thread * thrd ) {
    639639        /* paranoid */ verify( ! __preemption_enabled() );
    640640        /* paranoid */ verify( ready_schedule_islocked());
     
    651651}
    652652
    653 void unpark( thread$ * thrd ) {
     653void unpark( $thread * thrd ) {
    654654        if( !thrd ) return;
    655655
     
    675675        // Should never return
    676676        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;
    679679
    680680                // Lock the monitor now
     
    688688                /* paranoid */ verify( kernelTLS().this_thread == thrd );
    689689                /* 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 );
    692692
    693693                thrd->state = Halting;
     
    707707bool force_yield( __Preemption_Reason reason ) {
    708708        __disable_interrupts_checked();
    709                 thread$ * thrd = kernelTLS().this_thread;
     709                $thread * thrd = kernelTLS().this_thread;
    710710                /* paranoid */ verify(thrd->state == Active);
    711711
     
    819819//=============================================================================================
    820820void __kernel_abort_msg( char * abort_text, int abort_text_size ) {
    821         thread$ * thrd = __cfaabi_tls.this_thread;
     821        $thread * thrd = __cfaabi_tls.this_thread;
    822822
    823823        if(thrd) {
Note: See TracChangeset for help on using the changeset viewer.