Changeset e8e457e
- Timestamp:
- Apr 10, 2019, 11:37:21 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 5c1a531
- Parents:
- 69a61d2
- Location:
- libcfa/src/concurrency
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified libcfa/src/concurrency/coroutine.cfa ¶
r69a61d2 re8e457e 138 138 139 139 // context switch to specified coroutine 140 verify( src->context.SP );141 140 verify( dst->context.SP ); 142 141 CtxSwitch( &src->context, &dst->context ); -
TabularUnified libcfa/src/concurrency/invoke.c ¶
r69a61d2 re8e457e 29 29 extern void __suspend_internal(void); 30 30 extern void __leave_coroutine( struct coroutine_desc * ); 31 extern void __finish_creation( struct coroutine_desc * );31 extern void __finish_creation( struct thread_desc * ); 32 32 extern void __leave_thread_monitor( struct thread_desc * this ); 33 33 extern void disable_interrupts(); … … 93 93 // First suspend, once the thread arrives here, 94 94 // the function pointer to main can be invalidated without risk 95 __finish_creation(&thrd->self_cor); 96 97 // Restore the last to NULL, we clobbered because of the thunk problem 98 thrd->self_cor.last = NULL; 95 __finish_creation( thrd ); 99 96 100 97 // Officially start the thread by enabling preemption -
TabularUnified libcfa/src/concurrency/invoke.h ¶
r69a61d2 re8e457e 64 64 struct __stack_context_t { 65 65 void * SP; 66 67 66 void * FP; 68 67 // copy of global UNIX variable errno … … 105 104 struct __stack_info_t stack; 106 105 107 // textual name for coroutine/task , initialized by uC++ generated code106 // textual name for coroutine/task 108 107 const char * name; 109 108 … … 164 163 struct thread_desc { 165 164 // Core threading fields 165 // context that is switch during a CtxSwitch 166 struct __stack_context_t context; 167 168 // current execution status for coroutine 169 enum coroutine_state state; 170 166 171 // coroutine body used to store context 167 172 struct coroutine_desc self_cor; -
TabularUnified libcfa/src/concurrency/kernel.cfa ¶
r69a61d2 re8e457e 106 106 107 107 void ?{}( thread_desc & this, current_stack_info_t * info) with( this ) { 108 state = Start; 108 109 self_cor{ info }; 109 110 curr_cor = &self_cor; … … 239 240 // runThread runs a thread by context switching 240 241 // from the processor coroutine to the target thread 241 static void runThread(processor * this, thread_desc * dst) { 242 assert(dst->curr_cor); 242 static void runThread(processor * this, thread_desc * thrd_dst) { 243 243 coroutine_desc * proc_cor = get_coroutine(this->runner); 244 coroutine_desc * thrd_cor = dst->curr_cor;245 244 246 245 // Reset the terminating actions here … … 248 247 249 248 // Update global state 250 kernelTLS.this_thread = dst; 251 252 // Context Switch to the thread 253 ThreadCtxSwitch(proc_cor, thrd_cor); 254 // when ThreadCtxSwitch returns we are back in the processor coroutine 249 kernelTLS.this_thread = thrd_dst; 250 251 // set state of processor coroutine to inactive and the thread to active 252 proc_cor->state = proc_cor->state == Halted ? Halted : Inactive; 253 thrd_dst->state = Active; 254 255 // set context switch to the thread that the processor is executing 256 verify( thrd_dst->context.SP ); 257 CtxSwitch( &proc_cor->context, &thrd_dst->context ); 258 // when CtxSwitch returns we are back in the processor coroutine 259 260 // set state of processor coroutine to active and the thread to inactive 261 thrd_dst->state = thrd_dst->state == Halted ? Halted : Inactive; 262 proc_cor->state = Active; 255 263 } 256 264 … … 258 266 static void returnToKernel() { 259 267 coroutine_desc * proc_cor = get_coroutine(kernelTLS.this_processor->runner); 260 coroutine_desc * thrd_cor = kernelTLS.this_thread->curr_cor; 261 ThreadCtxSwitch(thrd_cor, proc_cor); 268 thread_desc * thrd_src = kernelTLS.this_thread; 269 270 // set state of current coroutine to inactive 271 thrd_src->state = thrd_src->state == Halted ? Halted : Inactive; 272 proc_cor->state = Active; 273 274 // set new coroutine that the processor is executing 275 // and context switch to it 276 verify( proc_cor->context.SP ); 277 CtxSwitch( &thrd_src->context, &proc_cor->context ); 278 279 // set state of new coroutine to active 280 proc_cor->state = proc_cor->state == Halted ? Halted : Inactive; 281 thrd_src->state = Active; 262 282 } 263 283 … … 343 363 344 364 // KERNEL_ONLY 345 void kernel_first_resume( processor * this) {346 coroutine_desc * src = mainThread->curr_cor;365 void kernel_first_resume( processor * this ) { 366 thread_desc * src = mainThread; 347 367 coroutine_desc * dst = get_coroutine(this->runner); 348 368 … … 354 374 verify( ! kernelTLS.preemption_state.enabled ); 355 375 356 dst->last = src;357 dst->starter = dst->starter ? dst->starter : src;376 dst->last = &src->self_cor; 377 dst->starter = dst->starter ? dst->starter : &src->self_cor; 358 378 359 379 // set state of current coroutine to inactive … … 378 398 } 379 399 400 // KERNEL_ONLY 401 void kernel_last_resume( processor * this ) { 402 coroutine_desc * src = &mainThread->self_cor; 403 coroutine_desc * dst = get_coroutine(this->runner); 404 405 verify( ! kernelTLS.preemption_state.enabled ); 406 verify( dst->starter == src ); 407 verify( dst->context.SP ); 408 409 // context switch to the processor 410 CtxSwitch( &src->context, &dst->context ); 411 } 412 380 413 //----------------------------------------------------------------------------- 381 414 // Scheduler routines … … 384 417 void ScheduleThread( thread_desc * thrd ) { 385 418 verify( thrd ); 386 verify( thrd->s elf_cor.state != Halted );419 verify( thrd->state != Halted ); 387 420 388 421 verify( ! kernelTLS.preemption_state.enabled ); … … 626 659 // which is currently here 627 660 __atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE); 628 returnToKernel();661 kernel_last_resume( kernelTLS.this_processor ); 629 662 mainThread->self_cor.state = Halted; 630 663 -
TabularUnified libcfa/src/concurrency/thread.cfa ¶
r69a61d2 re8e457e 31 31 // Thread ctors and dtors 32 32 void ?{}(thread_desc & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) { 33 context{ NULL, NULL }; 33 34 self_cor{ name, storage, storageSize }; 34 verify(&self_cor);35 state = Start; 35 36 curr_cor = &self_cor; 36 37 self_mon.owner = &this; … … 73 74 forall( dtype T | is_thread(T) ) 74 75 void __thrd_start( T& this ) { 75 coroutine_desc* thrd_c = get_coroutine(this); 76 thread_desc * thrd_h = get_thread (this); 77 thrd_c->last = TL_GET( this_thread )->curr_cor; 78 79 // __cfaabi_dbg_print_safe("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 76 thread_desc * this_thrd = get_thread(this); 77 thread_desc * curr_thrd = TL_GET( this_thread ); 80 78 81 79 disable_interrupts(); 82 assert( thrd_c->stack.storage );83 80 CtxStart(&this, CtxInvokeThread); 84 verify( thrd_c->last->context.SP );85 verify( th rd_c->context.SP );86 CtxSwitch( & thrd_c->last->context, &thrd_c->context );81 this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP]; 82 verify( this_thrd->context.SP ); 83 CtxSwitch( &curr_thrd->context, &this_thrd->context ); 87 84 88 ScheduleThread(th rd_h);85 ScheduleThread(this_thrd); 89 86 enable_interrupts( __cfaabi_dbg_ctx ); 90 87 } … … 92 89 extern "C" { 93 90 // KERNEL ONLY 94 void __finish_creation(coroutine_desc * thrd_c) { 95 ThreadCtxSwitch( thrd_c, thrd_c->last ); 91 void __finish_creation(thread_desc * this) { 92 // set new coroutine that the processor is executing 93 // and context switch to it 94 verify( kernelTLS.this_thread != this ); 95 verify( kernelTLS.this_thread->context.SP ); 96 CtxSwitch( &this->context, &kernelTLS.this_thread->context ); 96 97 } 97 98 } … … 111 112 } 112 113 113 // KERNEL ONLY114 void ThreadCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {115 // set state of current coroutine to inactive116 src->state = src->state == Halted ? Halted : Inactive;117 dst->state = Active;118 119 // set new coroutine that the processor is executing120 // and context switch to it121 verify( dst->context.SP );122 CtxSwitch( &src->context, &dst->context );123 124 // set state of new coroutine to active125 dst->state = dst->state == Halted ? Halted : Inactive;126 src->state = Active;127 }128 129 114 // Local Variables: // 130 115 // mode: c //
Note: See TracChangeset
for help on using the changeset viewer.