Changes in libcfa/src/concurrency/invoke.c [ac2b598:2026bb6]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/invoke.c
rac2b598 r2026bb6 29 29 // Called from the kernel when starting a coroutine or task so must switch back to user mode. 30 30 31 extern struct $coroutine * __cfactx_cor_finish(void);32 extern void __ cfactx_cor_leave ( struct $coroutine* );33 extern void __ cfactx_thrd_leave();34 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 ); 35 35 extern void disable_interrupts() OPTIONAL_THREAD; 36 36 extern void enable_interrupts( __cfaabi_dbg_ctx_param ); 37 37 38 void __cfactx_invoke_coroutine(38 void CtxInvokeCoroutine( 39 39 void (*main)(void *), 40 struct coroutine_desc *(*get_coroutine)(void *), 40 41 void *this 41 42 ) { 42 // Finish setting up the coroutine by setting its state 43 struct $coroutine * cor = __cfactx_cor_finish(); 43 struct coroutine_desc* cor = get_coroutine( this ); 44 44 45 // Call the main of the coroutine 45 if(cor->state == Primed) { 46 __suspend_internal(); 47 } 48 49 cor->state = Active; 50 46 51 main( this ); 47 52 48 53 //Final suspend, should never return 49 __ cfactx_cor_leave( cor );54 __leave_coroutine( cor ); 50 55 __cabi_abort( "Resumed dead coroutine" ); 51 56 } 52 57 53 static _Unwind_Reason_Code _ _cfactx_coroutine_unwindstop(58 static _Unwind_Reason_Code _CtxCoroutine_UnwindStop( 54 59 __attribute((__unused__)) int version, 55 60 _Unwind_Action actions, … … 62 67 // We finished unwinding the coroutine, 63 68 // leave it 64 __ cfactx_cor_leave( param );69 __leave_coroutine( param ); 65 70 __cabi_abort( "Resumed dead coroutine" ); 66 71 } … … 70 75 } 71 76 72 void _ _cfactx_coroutine_unwind(struct _Unwind_Exception * storage, struct $coroutine* cor) __attribute__ ((__noreturn__));73 void _ _cfactx_coroutine_unwind(struct _Unwind_Exception * storage, struct $coroutine* cor) {74 _Unwind_Reason_Code ret = _Unwind_ForcedUnwind( storage, _ _cfactx_coroutine_unwindstop, cor );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 ); 75 80 printf("UNWIND ERROR %d after force unwind\n", ret); 76 81 abort(); 77 82 } 78 83 79 void __cfactx_invoke_thread( 84 void CtxInvokeThread( 85 void (*dtor)(void *), 80 86 void (*main)(void *), 87 struct thread_desc *(*get_thread)(void *), 81 88 void *this 82 89 ) { 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 83 97 // Officially start the thread by enabling preemption 84 98 enable_interrupts( __cfaabi_dbg_ctx ); … … 94 108 // The order of these 4 operations is very important 95 109 //Final suspend, should never return 96 __ cfactx_thrd_leave();110 __leave_thread_monitor( thrd ); 97 111 __cabi_abort( "Resumed dead thread" ); 98 112 } 99 113 100 void __cfactx_start( 114 115 void CtxStart( 101 116 void (*main)(void *), 102 struct $coroutine * cor,117 struct coroutine_desc *(*get_coroutine)(void *), 103 118 void *this, 104 119 void (*invoke)(void *) 105 120 ) { 121 struct coroutine_desc * cor = get_coroutine( this ); 106 122 struct __stack_t * stack = cor->stack.storage; 107 123 … … 122 138 123 139 fs->dummyReturn = NULL; 124 fs->argument[0] = main; // argument to invoke 125 fs->argument[1] = this; // argument to invoke 140 fs->argument[0] = this; // argument to invoke 126 141 fs->rturn = invoke; 127 142 … … 140 155 141 156 fs->dummyReturn = NULL; 142 fs->rturn = __cfactx_invoke_stub; 143 fs->fixedRegisters[0] = main; 144 fs->fixedRegisters[1] = this; 145 fs->fixedRegisters[2] = invoke; 157 fs->rturn = CtxInvokeStub; 158 fs->fixedRegisters[0] = this; 159 fs->fixedRegisters[1] = invoke; 146 160 147 161 #elif defined( __ARM_ARCH ) 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) 162 149 163 struct FakeStack { 150 164 float fpRegs[16]; // floating point registers … … 158 172 struct FakeStack *fs = (struct FakeStack *)cor->context.SP; 159 173 160 fs->intRegs[8] = __cfactx_invoke_stub;174 fs->intRegs[8] = CtxInvokeStub; 161 175 fs->arg[0] = this; 162 176 fs->arg[1] = invoke;
Note:
See TracChangeset
for help on using the changeset viewer.