Changeset 82c948c for src/libcfa


Ignore:
Timestamp:
Feb 6, 2018, 10:07:18 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
7323573
Parents:
0188a0b
Message:

Thread context switch no longer break coroutines.
Added corresponding test

Location:
src/libcfa/concurrency
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/invoke.h

    r0188a0b r82c948c  
    121121                // coroutine body used to store context
    122122                struct coroutine_desc  self_cor;
     123
     124                // current active context
     125                struct coroutine_desc * curr_cor;
    123126
    124127                // monitor body used for mutual exclusion
  • src/libcfa/concurrency/kernel.c

    r0188a0b r82c948c  
    108108void ?{}( thread_desc & this, current_stack_info_t * info) with( this ) {
    109109        self_cor{ info };
     110        curr_cor = &self_cor;
     111        self_mon.owner = &this;
     112        self_mon.recursion = 1;
     113        self_mon_p = &self_mon;
     114        next = NULL;
     115        __cfaabi_dbg_debug_do(
     116                dbg_next = NULL;
     117                dbg_prev = NULL;
     118                __cfaabi_dbg_thread_register(&this);
     119        )
     120
     121        monitors{ &self_mon_p, 1, (fptr_t)0 };
    110122}
    111123
     
    225237// from the processor coroutine to the target thread
    226238void runThread(processor * this, thread_desc * dst) {
     239        assert(dst->curr_cor);
    227240        coroutine_desc * proc_cor = get_coroutine(*this->runner);
    228         coroutine_desc * thrd_cor = get_coroutine(dst);
     241        coroutine_desc * thrd_cor = dst->curr_cor;
    229242
    230243        //Reset the terminating actions here
     
    237250        ThreadCtxSwitch(proc_cor, thrd_cor);
    238251        // when ThreadCtxSwitch returns we are back in the processor coroutine
     252}
     253
     254void returnToKernel() {
     255        coroutine_desc * proc_cor = get_coroutine(*this_processor->runner);
     256        coroutine_desc * thrd_cor = this_thread->curr_cor = this_coroutine;
     257        ThreadCtxSwitch(thrd_cor, proc_cor);
    239258}
    240259
     
    360379        disable_interrupts();
    361380        verify( !preemption_enabled );
    362         suspend();
     381        returnToKernel();
    363382        verify( !preemption_enabled );
    364383        enable_interrupts( __cfaabi_dbg_ctx );
     
    371390
    372391        verify( !preemption_enabled );
    373         suspend();
     392        returnToKernel();
    374393        verify( !preemption_enabled );
    375394
     
    383402
    384403        verify( !preemption_enabled );
    385         suspend();
     404        returnToKernel();
    386405        verify( !preemption_enabled );
    387406
     
    397416
    398417        verify( !preemption_enabled );
    399         suspend();
     418        returnToKernel();
    400419        verify( !preemption_enabled );
    401420
     
    410429
    411430        verify( !preemption_enabled );
    412         suspend();
     431        returnToKernel();
    413432        verify( !preemption_enabled );
    414433
     
    425444
    426445        verify( !preemption_enabled );
    427         suspend();
     446        returnToKernel();
    428447        verify( !preemption_enabled );
    429448
     
    437456        this_processor->finish.thrd        = thrd;
    438457
    439         suspend();
     458        returnToKernel();
    440459}
    441460
     
    502521        // which is currently here
    503522        mainProcessor->do_terminate = true;
    504         suspend();
     523        returnToKernel();
    505524
    506525        // THE SYSTEM IS NOW COMPLETELY STOPPED
  • src/libcfa/concurrency/thread.c

    r0188a0b r82c948c  
    3434        self_cor{};
    3535        self_cor.name = "Anonymous Coroutine";
     36        curr_cor = &self_cor;
    3637        self_mon.owner = &this;
    3738        self_mon.recursion = 1;
     
    104105        dst->state = Active;
    105106
    106         //update the last resumer
    107         dst->last = src;
    108 
    109107        // set new coroutine that the processor is executing
    110108        // and context switch to it
Note: See TracChangeset for help on using the changeset viewer.