Ignore:
File:
1 edited

Legend:

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

    r2026bb6 rac2b598  
    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 struct $coroutine * __cfactx_cor_finish(void);
     32extern void __cfactx_cor_leave ( struct $coroutine * );
     33extern void __cfactx_thrd_leave();
     34
    3535extern void disable_interrupts() OPTIONAL_THREAD;
    3636extern void enable_interrupts( __cfaabi_dbg_ctx_param );
    3737
    38 void CtxInvokeCoroutine(
     38void __cfactx_invoke_coroutine(
    3939        void (*main)(void *),
    40         struct coroutine_desc *(*get_coroutine)(void *),
    4140        void *this
    4241) {
    43         struct coroutine_desc* cor = get_coroutine( this );
     42        // Finish setting up the coroutine by setting its state
     43        struct $coroutine * cor = __cfactx_cor_finish();
    4444
    45         if(cor->state == Primed) {
    46                 __suspend_internal();
    47         }
    48 
    49         cor->state = Active;
    50 
     45        // Call the main of the coroutine
    5146        main( this );
    5247
    5348        //Final suspend, should never return
    54         __leave_coroutine( cor );
     49        __cfactx_cor_leave( cor );
    5550        __cabi_abort( "Resumed dead coroutine" );
    5651}
    5752
    58 static _Unwind_Reason_Code _CtxCoroutine_UnwindStop(
     53static _Unwind_Reason_Code __cfactx_coroutine_unwindstop(
    5954        __attribute((__unused__)) int version,
    6055        _Unwind_Action actions,
     
    6762                // We finished unwinding the coroutine,
    6863                // leave it
    69                 __leave_coroutine( param );
     64                __cfactx_cor_leave( param );
    7065                __cabi_abort( "Resumed dead coroutine" );
    7166        }
     
    7570}
    7671
    77 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc * cor) __attribute__ ((__noreturn__));
    78 void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc * cor) {
    79         _Unwind_Reason_Code ret = _Unwind_ForcedUnwind( storage, _CtxCoroutine_UnwindStop, cor );
     72void __cfactx_coroutine_unwind(struct _Unwind_Exception * storage, struct $coroutine * cor) __attribute__ ((__noreturn__));
     73void __cfactx_coroutine_unwind(struct _Unwind_Exception * storage, struct $coroutine * cor) {
     74        _Unwind_Reason_Code ret = _Unwind_ForcedUnwind( storage, __cfactx_coroutine_unwindstop, cor );
    8075        printf("UNWIND ERROR %d after force unwind\n", ret);
    8176        abort();
    8277}
    8378
    84 void CtxInvokeThread(
    85         void (*dtor)(void *),
     79void __cfactx_invoke_thread(
    8680        void (*main)(void *),
    87         struct thread_desc *(*get_thread)(void *),
    8881        void *this
    8982) {
    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 
    9783        // Officially start the thread by enabling preemption
    9884        enable_interrupts( __cfaabi_dbg_ctx );
     
    10894        // The order of these 4 operations is very important
    10995        //Final suspend, should never return
    110         __leave_thread_monitor( thrd );
     96        __cfactx_thrd_leave();
    11197        __cabi_abort( "Resumed dead thread" );
    11298}
    11399
    114 
    115 void CtxStart(
     100void __cfactx_start(
    116101        void (*main)(void *),
    117         struct coroutine_desc *(*get_coroutine)(void *),
     102        struct $coroutine * cor,
    118103        void *this,
    119104        void (*invoke)(void *)
    120105) {
    121         struct coroutine_desc * cor = get_coroutine( this );
    122106        struct __stack_t * stack = cor->stack.storage;
    123107
     
    138122
    139123        fs->dummyReturn = NULL;
    140         fs->argument[0] = this;     // argument to invoke
     124        fs->argument[0] = main;     // argument to invoke
     125        fs->argument[1] = this;     // argument to invoke
    141126        fs->rturn = invoke;
    142127
     
    155140
    156141        fs->dummyReturn = NULL;
    157         fs->rturn = CtxInvokeStub;
    158         fs->fixedRegisters[0] = this;
    159         fs->fixedRegisters[1] = invoke;
     142        fs->rturn = __cfactx_invoke_stub;
     143        fs->fixedRegisters[0] = main;
     144        fs->fixedRegisters[1] = this;
     145        fs->fixedRegisters[2] = invoke;
    160146
    161147#elif defined( __ARM_ARCH )
    162 
     148#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)
    163149        struct FakeStack {
    164150                float fpRegs[16];                       // floating point registers
     
    172158        struct FakeStack *fs = (struct FakeStack *)cor->context.SP;
    173159
    174         fs->intRegs[8] = CtxInvokeStub;
     160        fs->intRegs[8] = __cfactx_invoke_stub;
    175161        fs->arg[0] = this;
    176162        fs->arg[1] = invoke;
Note: See TracChangeset for help on using the changeset viewer.