Ignore:
Timestamp:
Feb 4, 2020, 2:03:19 PM (21 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
74e3263
Parents:
e3fea42 (diff), 4f7b418 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    re3fea42 r52142c2  
    2929// Called from the kernel when starting a coroutine or task so must switch back to user mode.
    3030
    31 extern void __suspend_internal(void);
    32 extern void __leave_coroutine( struct coroutine_desc * );
    33 extern void __finish_creation( struct thread_desc * );
    34 extern void __leave_thread_monitor( struct thread_desc * this );
     31extern void __leave_coroutine ( struct coroutine_desc * );
     32extern struct coroutine_desc * __finish_coroutine(void);
     33extern void __leave_thread_monitor();
    3534extern void disable_interrupts() OPTIONAL_THREAD;
    3635extern void enable_interrupts( __cfaabi_dbg_ctx_param );
     
    3837void CtxInvokeCoroutine(
    3938        void (*main)(void *),
    40         struct coroutine_desc *(*get_coroutine)(void *),
    4139        void *this
    4240) {
    43         struct coroutine_desc* cor = get_coroutine( this );
     41        // Finish setting up the coroutine by setting its state
     42        struct coroutine_desc * cor = __finish_coroutine();
    4443
    45         if(cor->state == Primed) {
    46                 __suspend_internal();
    47         }
    48 
    49         cor->state = Active;
    50 
     44        // Call the main of the coroutine
    5145        main( this );
    5246
     
    8377
    8478void CtxInvokeThread(
    85         void (*dtor)(void *),
    8679        void (*main)(void *),
    87         struct thread_desc *(*get_thread)(void *),
    8880        void *this
    8981) {
    90         // Fetch the thread handle from the user defined thread structure
    91         struct thread_desc* thrd = get_thread( this );
    92 
    93         // First suspend, once the thread arrives here,
    94         // the function pointer to main can be invalidated without risk
    95         __finish_creation( thrd );
    96 
    9782        // Officially start the thread by enabling preemption
    9883        enable_interrupts( __cfaabi_dbg_ctx );
     
    10893        // The order of these 4 operations is very important
    10994        //Final suspend, should never return
    110         __leave_thread_monitor( thrd );
     95        __leave_thread_monitor();
    11196        __cabi_abort( "Resumed dead thread" );
    11297}
    11398
    114 
    11599void CtxStart(
    116100        void (*main)(void *),
    117         struct coroutine_desc *(*get_coroutine)(void *),
     101        struct coroutine_desc * cor,
    118102        void *this,
    119103        void (*invoke)(void *)
    120104) {
    121         struct coroutine_desc * cor = get_coroutine( this );
    122105        struct __stack_t * stack = cor->stack.storage;
    123106
     
    138121
    139122        fs->dummyReturn = NULL;
    140         fs->argument[0] = this;     // argument to invoke
     123        fs->argument[0] = main;     // argument to invoke
     124        fs->argument[1] = this;     // argument to invoke
    141125        fs->rturn = invoke;
    142126
     
    156140        fs->dummyReturn = NULL;
    157141        fs->rturn = CtxInvokeStub;
    158         fs->fixedRegisters[0] = this;
    159         fs->fixedRegisters[1] = invoke;
     142        fs->fixedRegisters[0] = main;
     143        fs->fixedRegisters[1] = this;
     144        fs->fixedRegisters[2] = invoke;
    160145
    161146#elif defined( __ARM_ARCH )
    162 
     147#error ARM needs to be upgrade to use to parameters like X86/X64 (A.K.A. : I broke this and do not know how to fix it)
    163148        struct FakeStack {
    164149                float fpRegs[16];                       // floating point registers
Note: See TracChangeset for help on using the changeset viewer.