Changeset b2f6113 for libcfa/src/concurrency/kernel.cfa
- Timestamp:
- Apr 4, 2019, 3:37:55 PM (5 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:
- 8c01e1b
- Parents:
- 2fabdc02
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r2fabdc02 rb2f6113 42 42 //----------------------------------------------------------------------------- 43 43 // Kernel storage 44 KERNEL_STORAGE(cluster, 45 KERNEL_STORAGE(processor, 46 KERNEL_STORAGE(thread_desc, 47 KERNEL_STORAGE( machine_context_t,mainThreadCtx);44 KERNEL_STORAGE(cluster, mainCluster); 45 KERNEL_STORAGE(processor, mainProcessor); 46 KERNEL_STORAGE(thread_desc, mainThread); 47 KERNEL_STORAGE(__stack_t, mainThreadCtx); 48 48 49 49 cluster * mainCluster; … … 54 54 struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters; 55 55 } 56 57 size_t __page_size = 0; 56 58 57 59 //----------------------------------------------------------------------------- … … 66 68 // Struct to steal stack 67 69 struct current_stack_info_t { 68 machine_context_t ctx;70 __stack_t * storage; // pointer to stack object 69 71 unsigned int size; // size of stack 70 72 void *base; // base of stack 71 void *storage; // pointer to stack72 73 void *limit; // stack grows towards stack limit 73 74 void *context; // address of cfa_context_t 74 void *top; // address of top of storage75 75 }; 76 76 77 77 void ?{}( current_stack_info_t & this ) { 78 CtxGet( this.ctx );79 this.base = this.ctx.FP;80 this. storage = this.ctx.SP;78 __stack_context_t ctx; 79 CtxGet( ctx ); 80 this.base = ctx.FP; 81 81 82 82 rlimit r; … … 86 86 this.limit = (void *)(((intptr_t)this.base) - this.size); 87 87 this.context = &storage_mainThreadCtx; 88 this.top = this.base;89 88 } 90 89 91 90 //----------------------------------------------------------------------------- 92 91 // Main thread construction 93 void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) {94 size = info->size;95 storage = info->storage;96 limit = info->limit;97 base = info->base;98 context = info->context;99 top = info->top;100 userStack = true;101 }102 92 103 93 void ?{}( coroutine_desc & this, current_stack_info_t * info) with( this ) { 104 stack{ info }; 94 context.errno_ = 0; 95 stack.storage = info->storage; 96 stack.userStack = true; 97 with(*stack.storage) { 98 size = info->size; 99 limit = info->limit; 100 base = info->base; 101 } 105 102 name = "Main Thread"; 106 errno_ = 0;107 103 state = Start; 108 104 starter = NULL; 105 last = NULL; 106 cancellation = NULL; 109 107 } 110 108 … … 312 310 // to waste the perfectly valid stack create by pthread. 313 311 current_stack_info_t info; 314 machine_context_t ctx;315 info. context= &ctx;312 __stack_t ctx; 313 info.storage = &ctx; 316 314 (proc->runner){ proc, &info }; 317 315 318 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack. base);316 __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage); 319 317 320 318 //Set global state … … 353 351 verify( ! kernelTLS.preemption_state.enabled ); 354 352 355 create_stack(&dst->stack, dst->stack.size);353 __stack_prepare( &dst->stack, 65000 ); 356 354 CtxStart(&this->runner, CtxInvokeCoroutine); 357 355 … … 372 370 373 371 // context switch to specified coroutine 374 assert( src->stack.context ); 375 CtxSwitch( src->stack.context, dst->stack.context ); 372 CtxSwitch( &src->context, &dst->context ); 376 373 // when CtxSwitch returns we are back in the src coroutine 377 374 … … 545 542 __cfaabi_dbg_print_safe("Kernel : Starting\n"); 546 543 544 __page_size = sysconf( _SC_PAGESIZE ); 545 547 546 __cfa_dbg_global_clusters.list{ __get }; 548 547 __cfa_dbg_global_clusters.lock{}; … … 559 558 mainThread = (thread_desc *)&storage_mainThread; 560 559 current_stack_info_t info; 560 info.storage = (__stack_t*)&storage_mainThreadCtx; 561 561 (*mainThread){ &info }; 562 562
Note: See TracChangeset
for help on using the changeset viewer.