Changeset 094476d for src/libcfa
- Timestamp:
- Mar 6, 2018, 12:10:53 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- caa649b
- Parents:
- 1f37ed02
- Location:
- src/libcfa/concurrency
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel
r1f37ed02 r094476d 79 79 80 80 // Processor 81 coroutine processorCtx_t { 82 struct processor * proc; 83 }; 84 81 85 // Wrapper around kernel threads 82 86 struct processor { 83 87 // Main state 84 88 // Coroutine ctx who does keeps the state of the processor 85 struct processorCtx_t *runner;89 struct processorCtx_t runner; 86 90 87 91 // Cluster from which to get threads -
src/libcfa/concurrency/kernel.c
r1f37ed02 r094476d 124 124 //----------------------------------------------------------------------------- 125 125 // Processor coroutine 126 void ?{}(processorCtx_t & this) {} 126 127 127 128 // Construct the processor context of the main processor … … 130 131 this.__cor.starter = NULL; 131 132 this.proc = proc; 132 proc->runner = &this;133 133 } 134 134 … … 137 137 (this.__cor){ info }; 138 138 this.proc = proc; 139 proc->runner = &this;140 139 } 141 140 … … 150 149 preemption_alarm = NULL; 151 150 pending_preemption = false; 151 runner.proc = &this; 152 152 153 153 start( &this ); … … 161 161 pending_preemption = false; 162 162 kernel_thread = pthread_self(); 163 164 this.runner = &runner; 163 runner.proc = &this; 164 165 165 __cfaabi_dbg_print_safe("Kernel : constructing main processor context %p\n", &runner); 166 166 runner{ &this }; … … 196 196 void main(processorCtx_t & runner) { 197 197 processor * this = runner.proc; 198 verify(this); 198 199 199 200 __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this); … … 241 242 void runThread(processor * this, thread_desc * dst) { 242 243 assert(dst->curr_cor); 243 coroutine_desc * proc_cor = get_coroutine( *this->runner);244 coroutine_desc * proc_cor = get_coroutine(this->runner); 244 245 coroutine_desc * thrd_cor = dst->curr_cor; 245 246 … … 256 257 257 258 void returnToKernel() { 258 coroutine_desc * proc_cor = get_coroutine( *this_processor->runner);259 coroutine_desc * proc_cor = get_coroutine(this_processor->runner); 259 260 coroutine_desc * thrd_cor = this_thread->curr_cor = this_coroutine; 260 261 ThreadCtxSwitch(thrd_cor, proc_cor); … … 317 318 machine_context_t ctx; 318 319 info.context = &ctx; 319 processorCtx_t proc_cor_storage ={ proc, &info };320 321 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);320 (proc->runner){ proc, &info }; 321 322 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.base); 322 323 323 324 //Set global state 324 this_coroutine = &proc->runner->__cor;325 this_coroutine = get_coroutine(proc->runner); 325 326 this_thread = NULL; 326 327 327 328 //We now have a proper context from which to schedule threads 328 __cfaabi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);329 __cfaabi_dbg_print_safe("Kernel : core %p created (%p, %p)\n", proc, &proc->runner, &ctx); 329 330 330 331 // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't … … 332 333 // back to here. Instead directly call the main since we already are on the 333 334 // appropriate stack. 334 proc_cor_storage.__cor.state = Active;335 main( proc _cor_storage);336 proc_cor_storage.__cor.state = Halted;335 get_coroutine(proc->runner)->state = Active; 336 main( proc->runner ); 337 get_coroutine(proc->runner)->state = Halted; 337 338 338 339 // Main routine of the core returned, the core is now fully terminated 339 __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, proc->runner);340 __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, &proc->runner); 340 341 341 342 return NULL; … … 352 353 void kernel_first_resume(processor * this) { 353 354 coroutine_desc * src = this_coroutine; 354 coroutine_desc * dst = get_coroutine( *this->runner);355 coroutine_desc * dst = get_coroutine(this->runner); 355 356 356 357 verify( !preemption_state.enabled ); 357 358 358 359 create_stack(&dst->stack, dst->stack.size); 359 CtxStart( this->runner, CtxInvokeCoroutine);360 CtxStart(&this->runner, CtxInvokeCoroutine); 360 361 361 362 verify( !preemption_state.enabled ); … … 411 412 verify( !preemption_state.enabled ); 412 413 lock( ready_queue_lock __cfaabi_dbg_ctx2 ); 413 //TEMP hack to find a bug414 if(this_processor != mainProcessor) {415 if(ready_queue.head == mainThread) {416 unlock( ready_queue_lock );417 return NULL;418 }419 }420 421 414 thread_desc * head = pop_head( ready_queue ); 422 415 unlock( ready_queue_lock ); … … 584 577 // Destroy the main processor and its context in reverse order of construction 585 578 // These were manually constructed so we need manually destroy them 586 ^( *mainProcessor->runner){};579 ^(mainProcessor->runner){}; 587 580 ^(mainProcessor){}; 588 581 -
src/libcfa/concurrency/kernel_private.h
r1f37ed02 r094476d 52 52 //----------------------------------------------------------------------------- 53 53 // Processor 54 coroutine processorCtx_t {55 processor * proc;56 };57 58 54 void main(processorCtx_t *); 59 55 void start(processor * this);
Note: See TracChangeset
for help on using the changeset viewer.