Changes in src/libcfa/concurrency/kernel.c [135b431:39fea2f]
- File:
-
- 1 edited
-
src/libcfa/concurrency/kernel.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r135b431 r39fea2f 73 73 }; 74 74 75 void ?{}( current_stack_info_t *this ) {76 CtxGet( this ->ctx );77 this ->base = this->ctx.FP;78 this ->storage = this->ctx.SP;75 void ?{}( current_stack_info_t & this ) { 76 CtxGet( this.ctx ); 77 this.base = this.ctx.FP; 78 this.storage = this.ctx.SP; 79 79 80 80 rlimit r; 81 81 getrlimit( RLIMIT_STACK, &r); 82 this->size = r.rlim_cur; 83 84 this->limit = (void *)(((intptr_t)this->base) - this->size); 85 this->context = &storage_mainThreadCtx; 86 this->top = this->base; 87 } 88 89 void ?{}( coStack_t * this, current_stack_info_t * info) { 90 this->size = info->size; 91 this->storage = info->storage; 92 this->limit = info->limit; 93 this->base = info->base; 94 this->context = info->context; 95 this->top = info->top; 96 this->userStack = true; 97 } 98 99 void ?{}( coroutine_desc * this, current_stack_info_t * info) { 100 (&this->stack){ info }; 101 this->name = "Main Thread"; 102 this->errno_ = 0; 103 this->state = Start; 104 } 105 106 void ?{}( thread_desc * this, current_stack_info_t * info) { 107 (&this->cor){ info }; 82 this.size = r.rlim_cur; 83 84 this.limit = (void *)(((intptr_t)this.base) - this.size); 85 this.context = &storage_mainThreadCtx; 86 this.top = this.base; 87 } 88 89 void ?{}( coStack_t & this, current_stack_info_t * info) { 90 this.size = info->size; 91 this.storage = info->storage; 92 this.limit = info->limit; 93 this.base = info->base; 94 this.context = info->context; 95 this.top = info->top; 96 this.userStack = true; 97 } 98 99 void ?{}( coroutine_desc & this, current_stack_info_t * info) { 100 (this.stack){ info }; 101 this.name = "Main Thread"; 102 this.errno_ = 0; 103 this.state = Start; 104 this.starter = NULL; 105 } 106 107 void ?{}( thread_desc & this, current_stack_info_t * info) { 108 (this.cor){ info }; 108 109 } 109 110 110 111 //----------------------------------------------------------------------------- 111 112 // Processor coroutine 112 void ?{}(processorCtx_t * this, processor * proc) { 113 (&this->__cor){ "Processor" }; 114 this->proc = proc; 115 proc->runner = this; 116 } 117 118 void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) { 119 (&this->__cor){ info }; 120 this->proc = proc; 121 proc->runner = this; 122 } 123 124 void ?{}(processor * this) { 113 114 // Construct the processor context of the main processor 115 void ?{}(processorCtx_t & this, processor * proc) { 116 (this.__cor){ "Processor" }; 117 this.__cor.starter = &mainThread->cor; 118 this.proc = proc; 119 proc->runner = &this; 120 } 121 122 // Construct the processor context of non-main processors 123 void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info) { 124 (this.__cor){ info }; 125 this.proc = proc; 126 proc->runner = &this; 127 } 128 129 void ?{}(processor & this) { 125 130 this{ mainCluster }; 126 131 } 127 132 128 void ?{}(processor *this, cluster * cltr) {129 this ->cltr = cltr;130 ( &this->terminated){ 0 };131 this ->do_terminate = false;132 this ->preemption_alarm = NULL;133 this ->pending_preemption = false;134 135 start( this );136 } 137 138 void ?{}(processor * this, cluster * cltr, processorCtx_t *runner) {139 this ->cltr = cltr;140 ( &this->terminated){ 0 };141 this ->do_terminate = false;142 this ->preemption_alarm = NULL;143 this ->pending_preemption = false;144 this ->kernel_thread = pthread_self();145 146 this ->runner =runner;147 LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", runner);148 runner{ this };149 } 150 151 void ^?{}(processor *this) {152 if( ! this ->do_terminate ) {153 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", this);154 this ->do_terminate = true;155 P( &this ->terminated );156 pthread_join( this ->kernel_thread, NULL );157 } 158 } 159 160 void ?{}(cluster *this) {161 ( &this->ready_queue ){};162 ( &this->ready_queue_lock ){};163 164 this ->preemption = default_preemption();165 } 166 167 void ^?{}(cluster *this) {133 void ?{}(processor & this, cluster * cltr) { 134 this.cltr = cltr; 135 (this.terminated){ 0 }; 136 this.do_terminate = false; 137 this.preemption_alarm = NULL; 138 this.pending_preemption = false; 139 140 start( &this ); 141 } 142 143 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) { 144 this.cltr = cltr; 145 (this.terminated){ 0 }; 146 this.do_terminate = false; 147 this.preemption_alarm = NULL; 148 this.pending_preemption = false; 149 this.kernel_thread = pthread_self(); 150 151 this.runner = &runner; 152 LIB_DEBUG_PRINT_SAFE("Kernel : constructing main processor context %p\n", &runner); 153 runner{ &this }; 154 } 155 156 void ^?{}(processor & this) { 157 if( ! this.do_terminate ) { 158 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this); 159 this.do_terminate = true; 160 P( &this.terminated ); 161 pthread_join( this.kernel_thread, NULL ); 162 } 163 } 164 165 void ?{}(cluster & this) { 166 ( this.ready_queue ){}; 167 ( this.ready_queue_lock ){}; 168 169 this.preemption = default_preemption(); 170 } 171 172 void ^?{}(cluster & this) { 168 173 169 174 } … … 173 178 //============================================================================================= 174 179 //Main of the processor contexts 175 void main(processorCtx_t *runner) {176 processor * this = runner ->proc;180 void main(processorCtx_t & runner) { 181 processor * this = runner.proc; 177 182 178 183 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this); … … 219 224 // from the processor coroutine to the target thread 220 225 void runThread(processor * this, thread_desc * dst) { 221 coroutine_desc * proc_cor = get_coroutine( this->runner);226 coroutine_desc * proc_cor = get_coroutine(*this->runner); 222 227 coroutine_desc * thrd_cor = get_coroutine(dst); 223 228 … … 301 306 // appropriate stack. 302 307 proc_cor_storage.__cor.state = Active; 303 main( &proc_cor_storage );308 main( proc_cor_storage ); 304 309 proc_cor_storage.__cor.state = Halted; 305 310 … … 443 448 mainThread = (thread_desc *)&storage_mainThread; 444 449 current_stack_info_t info; 445 mainThread{ &info };450 (*mainThread){ &info }; 446 451 447 452 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n"); … … 449 454 // Initialize the main cluster 450 455 mainCluster = (cluster *)&storage_mainCluster; 451 mainCluster{};456 (*mainCluster){}; 452 457 453 458 LIB_DEBUG_PRINT_SAFE("Kernel : main cluster ready\n"); … … 456 461 // (the coroutine that contains the processing control flow) 457 462 mainProcessor = (processor *)&storage_mainProcessor; 458 mainProcessor{ mainCluster,(processorCtx_t *)&storage_mainProcessorCtx };463 (*mainProcessor){ mainCluster, *(processorCtx_t *)&storage_mainProcessorCtx }; 459 464 460 465 //initialize the global state variables … … 473 478 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 474 479 // mainThread is on the ready queue when this call is made. 475 resume( mainProcessor->runner );480 resume( *mainProcessor->runner ); 476 481 477 482 … … 501 506 // Destroy the main processor and its context in reverse order of construction 502 507 // These were manually constructed so we need manually destroy them 503 ^( mainProcessor->runner){};508 ^(*mainProcessor->runner){}; 504 509 ^(mainProcessor){}; 505 510 … … 569 574 //----------------------------------------------------------------------------- 570 575 // Locks 571 void ?{}( spinlock *this ) {572 this ->lock = 0;573 } 574 void ^?{}( spinlock *this ) {576 void ?{}( spinlock & this ) { 577 this.lock = 0; 578 } 579 void ^?{}( spinlock & this ) { 575 580 576 581 } … … 606 611 } 607 612 608 void ?{}( semaphore *this, int count = 1 ) {609 ( &this->lock){};610 this ->count = count;611 ( &this->waiting){};612 } 613 void ^?{}(semaphore *this) {}613 void ?{}( semaphore & this, int count = 1 ) { 614 (this.lock){}; 615 this.count = count; 616 (this.waiting){}; 617 } 618 void ^?{}(semaphore & this) {} 614 619 615 620 void P(semaphore * this) { … … 645 650 //----------------------------------------------------------------------------- 646 651 // Queues 647 void ?{}( __thread_queue_t *this ) {648 this ->head = NULL;649 this ->tail = &this->head;652 void ?{}( __thread_queue_t & this ) { 653 this.head = NULL; 654 this.tail = &this.head; 650 655 } 651 656 … … 685 690 } 686 691 687 688 689 void ?{}( __condition_stack_t * this ) { 690 this->top = NULL; 692 void ?{}( __condition_stack_t & this ) { 693 this.top = NULL; 691 694 } 692 695
Note:
See TracChangeset
for help on using the changeset viewer.