Changes in / [52142c2:e3fea42]
- Files:
-
- 10 edited
-
libcfa/src/concurrency/CtxSwitch-x86_64.S (modified) (1 diff)
-
libcfa/src/concurrency/coroutine.cfa (modified) (2 diffs)
-
libcfa/src/concurrency/coroutine.hfa (modified) (2 diffs)
-
libcfa/src/concurrency/invoke.c (modified) (6 diffs)
-
libcfa/src/concurrency/kernel.cfa (modified) (3 diffs)
-
libcfa/src/concurrency/kernel_private.hfa (modified) (1 diff)
-
libcfa/src/concurrency/monitor.cfa (modified) (1 diff)
-
libcfa/src/concurrency/thread.cfa (modified) (3 diffs)
-
libcfa/src/concurrency/thread.hfa (modified) (1 diff)
-
src/Concurrency/Keywords.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/CtxSwitch-x86_64.S
r52142c2 re3fea42 87 87 CtxInvokeStub: 88 88 movq %rbx, %rdi 89 movq %r12, %rsi 90 jmp *%r13 89 jmp *%r12 91 90 .size CtxInvokeStub, .-CtxInvokeStub 92 91 -
libcfa/src/concurrency/coroutine.cfa
r52142c2 re3fea42 187 187 // is not inline (We can't inline Cforall in C) 188 188 extern "C" { 189 void __leave_coroutine( struct coroutine_desc * src ) { 189 void __suspend_internal(void) { 190 suspend(); 191 } 192 193 void __leave_coroutine( coroutine_desc * src ) { 190 194 coroutine_desc * starter = src->cancellation != 0 ? src->last : src->starter; 191 195 … … 203 207 CoroutineCtxSwitch( src, starter ); 204 208 } 205 206 struct coroutine_desc * __finish_coroutine(void) {207 struct coroutine_desc * cor = kernelTLS.this_thread->curr_cor;208 209 if(cor->state == Primed) {210 suspend();211 }212 213 cor->state = Active;214 215 return cor;216 }217 209 } 218 210 -
libcfa/src/concurrency/coroutine.hfa
r52142c2 re3fea42 61 61 // Start coroutine routines 62 62 extern "C" { 63 void CtxInvokeCoroutine(void (*main)(void *), void * this); 63 forall(dtype T | is_coroutine(T)) 64 void CtxInvokeCoroutine(T * this); 64 65 65 forall(dtype T)66 void CtxStart(void (*main)(T &), struct coroutine_desc * cor, T & this, void (*invoke)(void (*main)(void *), void*));66 forall(dtype T | is_coroutine(T)) 67 void CtxStart(T * this, void ( *invoke)(T *)); 67 68 68 69 extern void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc *) __attribute__ ((__noreturn__)); … … 128 129 129 130 if( unlikely(dst->context.SP == 0p) ) { 130 TL_GET( this_thread )->curr_cor = dst;131 131 __stack_prepare(&dst->stack, 65000); 132 CtxStart(main, dst, cor, CtxInvokeCoroutine); 133 TL_GET( this_thread )->curr_cor = src; 132 CtxStart(&cor, CtxInvokeCoroutine); 134 133 } 135 134 -
libcfa/src/concurrency/invoke.c
r52142c2 re3fea42 29 29 // Called from the kernel when starting a coroutine or task so must switch back to user mode. 30 30 31 extern void __leave_coroutine ( struct coroutine_desc * ); 32 extern struct coroutine_desc * __finish_coroutine(void); 33 extern void __leave_thread_monitor(); 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 ); 34 35 extern void disable_interrupts() OPTIONAL_THREAD; 35 36 extern void enable_interrupts( __cfaabi_dbg_ctx_param ); … … 37 38 void CtxInvokeCoroutine( 38 39 void (*main)(void *), 40 struct coroutine_desc *(*get_coroutine)(void *), 39 41 void *this 40 42 ) { 41 // Finish setting up the coroutine by setting its state 42 struct coroutine_desc * cor = __finish_coroutine(); 43 struct coroutine_desc* cor = get_coroutine( this ); 43 44 44 // Call the main of the coroutine 45 if(cor->state == Primed) { 46 __suspend_internal(); 47 } 48 49 cor->state = Active; 50 45 51 main( this ); 46 52 … … 77 83 78 84 void CtxInvokeThread( 85 void (*dtor)(void *), 79 86 void (*main)(void *), 87 struct thread_desc *(*get_thread)(void *), 80 88 void *this 81 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 82 97 // Officially start the thread by enabling preemption 83 98 enable_interrupts( __cfaabi_dbg_ctx ); … … 93 108 // The order of these 4 operations is very important 94 109 //Final suspend, should never return 95 __leave_thread_monitor( );110 __leave_thread_monitor( thrd ); 96 111 __cabi_abort( "Resumed dead thread" ); 97 112 } 98 113 114 99 115 void CtxStart( 100 116 void (*main)(void *), 101 struct coroutine_desc * cor,117 struct coroutine_desc *(*get_coroutine)(void *), 102 118 void *this, 103 119 void (*invoke)(void *) 104 120 ) { 121 struct coroutine_desc * cor = get_coroutine( this ); 105 122 struct __stack_t * stack = cor->stack.storage; 106 123 … … 121 138 122 139 fs->dummyReturn = NULL; 123 fs->argument[0] = main; // argument to invoke 124 fs->argument[1] = this; // argument to invoke 140 fs->argument[0] = this; // argument to invoke 125 141 fs->rturn = invoke; 126 142 … … 140 156 fs->dummyReturn = NULL; 141 157 fs->rturn = CtxInvokeStub; 142 fs->fixedRegisters[0] = main; 143 fs->fixedRegisters[1] = this; 144 fs->fixedRegisters[2] = invoke; 158 fs->fixedRegisters[0] = this; 159 fs->fixedRegisters[1] = invoke; 145 160 146 161 #elif defined( __ARM_ARCH ) 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) 162 148 163 struct FakeStack { 149 164 float fpRegs[16]; // floating point registers -
libcfa/src/concurrency/kernel.cfa
r52142c2 re3fea42 469 469 ); 470 470 471 Abort( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); 471 Abort( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); 472 472 473 473 Abort( pthread_create( pthread, &attr, start, arg ), "pthread_create" ); … … 490 490 verify( ! kernelTLS.preemption_state.enabled ); 491 491 492 kernelTLS.this_thread->curr_cor = dst;493 492 __stack_prepare( &dst->stack, 65000 ); 494 CtxStart( main, dst,this->runner, CtxInvokeCoroutine);493 CtxStart(&this->runner, CtxInvokeCoroutine); 495 494 496 495 verify( ! kernelTLS.preemption_state.enabled ); … … 506 505 CtxSwitch( &src->context, &dst->context ); 507 506 // when CtxSwitch returns we are back in the src coroutine 508 509 mainThread->curr_cor = &mainThread->self_cor;510 507 511 508 // set state of new coroutine to active -
libcfa/src/concurrency/kernel_private.hfa
r52142c2 re3fea42 88 88 // Threads 89 89 extern "C" { 90 void CtxInvokeThread(void (*main)(void *), void * this); 90 forall(dtype T | is_thread(T)) 91 void CtxInvokeThread(T * this); 91 92 } 92 93 -
libcfa/src/concurrency/monitor.cfa
r52142c2 re3fea42 243 243 // last routine called by a thread. 244 244 // Should never return 245 void __leave_thread_monitor() { 246 thread_desc * thrd = TL_GET( this_thread ); 245 void __leave_thread_monitor( thread_desc * thrd ) { 247 246 monitor_desc * this = &thrd->self_mon; 248 247 -
libcfa/src/concurrency/thread.cfa
r52142c2 re3fea42 58 58 void ?{}( scoped(T)& this ) with( this ) { 59 59 handle{}; 60 __thrd_start(handle , main);60 __thrd_start(handle); 61 61 } 62 62 … … 64 64 void ?{}( scoped(T)& this, P params ) with( this ) { 65 65 handle{ params }; 66 __thrd_start(handle , main);66 __thrd_start(handle); 67 67 } 68 68 … … 75 75 // Starting and stopping threads 76 76 forall( dtype T | is_thread(T) ) 77 void __thrd_start( T & this, void (*main_p)(T &)) {77 void __thrd_start( T& this ) { 78 78 thread_desc * this_thrd = get_thread(this); 79 79 thread_desc * curr_thrd = TL_GET( this_thread ); 80 80 81 81 disable_interrupts(); 82 CtxStart(main_p, get_coroutine(this), this, CtxInvokeThread); 83 82 CtxStart(&this, CtxInvokeThread); 84 83 this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP]; 85 84 verify( this_thrd->context.SP ); 86 //CtxSwitch( &curr_thrd->context, &this_thrd->context );85 CtxSwitch( &curr_thrd->context, &this_thrd->context ); 87 86 88 87 ScheduleThread(this_thrd); 89 88 enable_interrupts( __cfaabi_dbg_ctx ); 89 } 90 91 extern "C" { 92 // KERNEL ONLY 93 void __finish_creation(thread_desc * this) { 94 // set new coroutine that the processor is executing 95 // and context switch to it 96 verify( kernelTLS.this_thread != this ); 97 verify( kernelTLS.this_thread->context.SP ); 98 CtxSwitch( &this->context, &kernelTLS.this_thread->context ); 99 } 90 100 } 91 101 -
libcfa/src/concurrency/thread.hfa
r52142c2 re3fea42 54 54 55 55 forall( dtype T | is_thread(T) ) 56 void __thrd_start( T & this , void (*)(T &));56 void __thrd_start( T & this ); 57 57 58 58 //----------------------------------------------------------------------------- -
src/Concurrency/Keywords.cc
r52142c2 re3fea42 716 716 new UntypedExpr( 717 717 new NameExpr( "__thrd_start" ), 718 { new VariableExpr( param ) , new NameExpr("main")}718 { new VariableExpr( param ) } 719 719 ) 720 720 )
Note:
See TracChangeset
for help on using the changeset viewer.