Ignore:
File:
1 edited

Legend:

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

    r0190480 rb4b63e8  
    237237        $coroutine * proc_cor = get_coroutine(this->runner);
    238238
    239         // Update global state
    240         kernelTLS.this_thread = thrd_dst;
    241 
    242239        // set state of processor coroutine to inactive
    243240        verify(proc_cor->state == Active);
     
    249246                thrd_dst->state = Active;
    250247
    251                 __cfaabi_dbg_debug_do(
    252                         thrd_dst->park_stale   = true;
    253                         thrd_dst->unpark_stale = true;
    254                 )
     248                // Update global state
     249                kernelTLS.this_thread = thrd_dst;
    255250
    256251                /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    257252                /* paranoid */ verify( kernelTLS.this_thread == thrd_dst );
     253                /* paranoid */ verify( thrd_dst->context.SP );
    258254                /* 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
    259255                /* 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
    260259
    261260                // set context switch to the thread that the processor is executing
    262                 verify( thrd_dst->context.SP );
    263261                __cfactx_switch( &proc_cor->context, &thrd_dst->context );
    264262                // when __cfactx_switch returns we are back in the processor coroutine
    265263
     264                /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd_dst->canary );
    266265                /* 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 );
    267266                /* 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 );
    268268                /* paranoid */ verify( kernelTLS.this_thread == thrd_dst );
    269269                /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    270270
     271                // Reset global state
     272                kernelTLS.this_thread = 0p;
    271273
    272274                // We just finished running a thread, there are a few things that could have happened.
     
    286288                        // The thread has halted, it should never be scheduled/run again
    287289                        // We may need to wake someone up here since
    288                         unpark( this->destroyer __cfaabi_dbg_ctx2 );
     290                        unpark( this->destroyer );
    289291                        this->destroyer = 0p;
    290292                        break RUNNING;
     
    296298                // set state of processor coroutine to active and the thread to inactive
    297299                int old_ticket = __atomic_fetch_sub(&thrd_dst->ticket, 1, __ATOMIC_SEQ_CST);
    298                 __cfaabi_dbg_debug_do( thrd_dst->park_result = old_ticket; )
    299300                switch(old_ticket) {
    300301                        case 1:
     
    313314        // Just before returning to the processor, set the processor coroutine to active
    314315        proc_cor->state = Active;
    315         kernelTLS.this_thread = 0p;
    316316
    317317        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     
    334334                        __x87_store;
    335335                #endif
    336                 verify( proc_cor->context.SP );
     336                /* paranoid */ verify( proc_cor->context.SP );
     337                /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd_src->canary );
    337338                __cfactx_switch( &thrd_src->context, &proc_cor->context );
     339                /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd_src->canary );
    338340                #if defined( __i386 ) || defined( __x86_64 )
    339341                        __x87_load;
     
    367369        /* paranoid */ #endif
    368370        /* paranoid */ verifyf( thrd->link.next == 0p, "Expected null got %p", thrd->link.next );
     371        /* paranoid */ verify( 0x0D15EA5E0D15EA5E == thrd->canary );
     372
    369373
    370374        if (thrd->preempted == __NO_PREEMPTION) thrd->state = Ready;
     
    403407
    404408// KERNEL ONLY unpark with out disabling interrupts
    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 
     409void __unpark(  struct __processor_id_t * id, $thread * thrd ) {
    409410        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; )
    411411        switch(old_ticket) {
    412412                case 1:
     
    426426}
    427427
    428 void unpark( $thread * thrd __cfaabi_dbg_ctx_param2 ) {
     428void unpark( $thread * thrd ) {
    429429        if( !thrd ) return;
    430430
    431431        disable_interrupts();
    432         __unpark( (__processor_id_t*)kernelTLS.this_processor, thrd __cfaabi_dbg_ctx_fwd2 );
     432        __unpark( (__processor_id_t*)kernelTLS.this_processor, thrd );
    433433        enable_interrupts( __cfaabi_dbg_ctx );
    434434}
    435435
    436 void park( __cfaabi_dbg_ctx_param ) {
     436void park( void ) {
    437437        /* paranoid */ verify( kernelTLS.preemption_state.enabled );
    438438        disable_interrupts();
    439439        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    440440        /* paranoid */ verify( kernelTLS.this_thread->preempted == __NO_PREEMPTION );
    441 
    442         // record activity
    443         __cfaabi_dbg_record_thrd( *kernelTLS.this_thread, true, caller );
    444441
    445442        returnToKernel();
     
    521518        disable_interrupts();
    522519                /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    523                 bool ret = post( this->idle );
     520                post( this->idle );
    524521        enable_interrupts( __cfaabi_dbg_ctx );
    525522}
     
    649646                // atomically release spin lock and block
    650647                unlock( lock );
    651                 park( __cfaabi_dbg_ctx );
     648                park();
    652649                return true;
    653650        }
     
    670667
    671668        // make new owner
    672         unpark( thrd __cfaabi_dbg_ctx2 );
     669        unpark( thrd );
    673670
    674671        return thrd != 0p;
     
    681678        count += diff;
    682679        for(release) {
    683                 unpark( pop_head( waiting ) __cfaabi_dbg_ctx2 );
     680                unpark( pop_head( waiting ) );
    684681        }
    685682
     
    697694                        this.prev_thrd = kernelTLS.this_thread;
    698695                }
    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                 }
    710696        }
    711697)
Note: See TracChangeset for help on using the changeset viewer.