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