Changeset e60e0dc for src/libcfa/concurrency/kernel.c
- Timestamp:
- Jul 17, 2017, 3:54:02 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:
- 5bd0aad
- Parents:
- b706db1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
rb706db1 re60e0dc 47 47 KERNEL_STORAGE(cluster, systemCluster); 48 48 KERNEL_STORAGE(system_proc_t, systemProcessor); 49 KERNEL_STORAGE(event_kernel_t, event_kernel); 49 50 KERNEL_STORAGE(thread_desc, mainThread); 50 51 KERNEL_STORAGE(machine_context_t, mainThreadCtx); … … 52 53 cluster * systemCluster; 53 54 system_proc_t * systemProcessor; 55 event_kernel_t * event_kernel; 54 56 thread_desc * mainThread; 55 57 … … 131 133 this->cltr = cltr; 132 134 (&this->terminated){ 0 }; 133 this-> is_terminated= false;135 this->do_terminate = false; 134 136 this->preemption_alarm = NULL; 135 this->preemption = default_preemption();136 137 this->pending_preemption = false; 137 138 … … 142 143 this->cltr = cltr; 143 144 (&this->terminated){ 0 }; 144 this-> is_terminated= false;145 this->do_terminate = false; 145 146 this->preemption_alarm = NULL; 146 this->preemption = default_preemption();147 147 this->pending_preemption = false; 148 148 this->kernel_thread = pthread_self(); … … 156 156 157 157 void ?{}(system_proc_t * this, cluster * cltr, processorCtx_t * runner) { 158 (&this->proc){ cltr, runner }; 159 } 160 161 void ?{}(event_kernel_t * this) { 158 162 (&this->alarms){}; 159 (&this->alarm_lock){}; 160 this->pending_alarm = false; 161 162 (&this->proc){ cltr, runner }; 163 (&this->lock){}; 163 164 164 165 verify( validate( &this->alarms ) ); … … 166 167 167 168 void ^?{}(processor * this) { 168 if( ! this-> is_terminated) {169 if( ! this->do_terminate ) { 169 170 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", this); 170 this-> is_terminated= true;171 this->do_terminate = true; 171 172 P( &this->terminated ); 172 173 pthread_join( this->kernel_thread, NULL ); … … 176 177 void ?{}(cluster * this) { 177 178 ( &this->ready_queue ){}; 178 ( &this->lock ){}; 179 ( &this->ready_queue_lock ){}; 180 181 this->preemption = default_preemption(); 179 182 } 180 183 … … 199 202 200 203 thread_desc * readyThread = NULL; 201 for( unsigned int spin_count = 0; ! this-> is_terminated; spin_count++ )204 for( unsigned int spin_count = 0; ! this->do_terminate; spin_count++ ) 202 205 { 203 206 readyThread = nextThread( this->cltr ); … … 343 346 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 344 347 345 lock( &systemProcessor->proc.cltr-> lock DEBUG_CTX2 );348 lock( &systemProcessor->proc.cltr->ready_queue_lock DEBUG_CTX2 ); 346 349 append( &systemProcessor->proc.cltr->ready_queue, thrd ); 347 unlock( &systemProcessor->proc.cltr-> lock );350 unlock( &systemProcessor->proc.cltr->ready_queue_lock ); 348 351 349 352 verify( disable_preempt_count > 0 ); … … 352 355 thread_desc * nextThread(cluster * this) { 353 356 verify( disable_preempt_count > 0 ); 354 lock( &this-> lock DEBUG_CTX2 );357 lock( &this->ready_queue_lock DEBUG_CTX2 ); 355 358 thread_desc * head = pop_head( &this->ready_queue ); 356 unlock( &this-> lock );359 unlock( &this->ready_queue_lock ); 357 360 verify( disable_preempt_count > 0 ); 358 361 return head; … … 470 473 systemProcessor{ systemCluster, (processorCtx_t *)&systemProcessorCtxStorage }; 471 474 475 // Initialize the event kernel 476 event_kernel = (event_kernel_t *)&event_kernelStorage; 477 event_kernel{}; 478 472 479 // Add the main thread to the ready queue 473 480 // once resume is called on systemProcessor->runner the mainThread needs to be scheduled like any normal thread … … 504 511 // When its coroutine terminates, it return control to the mainThread 505 512 // which is currently here 506 systemProcessor->proc. is_terminated= true;513 systemProcessor->proc.do_terminate = true; 507 514 suspend(); 508 515
Note: See TracChangeset
for help on using the changeset viewer.