Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d908563
Parents:
6a9d4b4 (diff), 292642a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

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

    r6a9d4b4 r933f32f  
    3131// Thread ctors and dtors
    3232void ?{}(thread_desc & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) {
     33        context{ NULL, NULL };
    3334        self_cor{ name, storage, storageSize };
    34         verify(&self_cor);
     35        state = Start;
    3536        curr_cor = &self_cor;
    3637        self_mon.owner = &this;
     
    7374forall( dtype T | is_thread(T) )
    7475void __thrd_start( T& this ) {
    75         coroutine_desc* thrd_c = get_coroutine(this);
    76         thread_desc   * thrd_h = get_thread   (this);
    77         thrd_c->last = TL_GET( this_coroutine );
    78 
    79         // __cfaabi_dbg_print_safe("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);
     76        thread_desc * this_thrd = get_thread(this);
     77        thread_desc * curr_thrd = TL_GET( this_thread );
    8078
    8179        disable_interrupts();
    82         create_stack(&thrd_c->stack, thrd_c->stack.size);
    83         kernelTLS.this_coroutine = thrd_c;
    8480        CtxStart(&this, CtxInvokeThread);
    85         assert( thrd_c->last->stack.context );
    86         CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
     81        this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP];
     82        verify( this_thrd->context.SP );
     83        CtxSwitch( &curr_thrd->context, &this_thrd->context );
    8784
    88         ScheduleThread(thrd_h);
     85        ScheduleThread(this_thrd);
    8986        enable_interrupts( __cfaabi_dbg_ctx );
    9087}
     
    9289extern "C" {
    9390        // KERNEL ONLY
    94         void __finish_creation(void) {
    95                 coroutine_desc* thrd_c = kernelTLS.this_coroutine;
    96                 ThreadCtxSwitch( thrd_c, thrd_c->last );
     91        void __finish_creation(thread_desc * this) {
     92                // set new coroutine that the processor is executing
     93                // and context switch to it
     94                verify( kernelTLS.this_thread != this );
     95                verify( kernelTLS.this_thread->context.SP );
     96                CtxSwitch( &this->context, &kernelTLS.this_thread->context );
    9797        }
    9898}
     
    112112}
    113113
    114 // KERNEL ONLY
    115 void ThreadCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
    116         // set state of current coroutine to inactive
    117         src->state = src->state == Halted ? Halted : Inactive;
    118         dst->state = Active;
    119 
    120         // set new coroutine that the processor is executing
    121         // and context switch to it
    122         kernelTLS.this_coroutine = dst;
    123         assert( src->stack.context );
    124         CtxSwitch( src->stack.context, dst->stack.context );
    125         kernelTLS.this_coroutine = src;
    126 
    127         // set state of new coroutine to active
    128         dst->state = dst->state == Halted ? Halted : Inactive;
    129         src->state = Active;
    130 }
    131 
    132114// Local Variables: //
    133115// mode: c //
Note: See TracChangeset for help on using the changeset viewer.