Changeset fa21ac9
- Timestamp:
- Jun 5, 2017, 11:42:05 AM (8 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:
- b3c36f4
- Parents:
- 2f9a722
- Location:
- src/libcfa/concurrency
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel
r2f9a722 rfa21ac9 94 94 95 95 // Local Variables: // 96 // mode: c//97 // tab-width: 4//96 // mode: CFA // 97 // tab-width: 6 // 98 98 // End: // -
src/libcfa/concurrency/kernel.c
r2f9a722 rfa21ac9 47 47 KERNEL_STORAGE(processorCtx_t, systemProcessorCtx); 48 48 KERNEL_STORAGE(cluster, systemCluster); 49 KERNEL_STORAGE( processor, systemProcessor);49 KERNEL_STORAGE(system_proc_t, systemProcessor); 50 50 KERNEL_STORAGE(thread_desc, mainThread); 51 51 KERNEL_STORAGE(machine_context_t, mainThread_context); 52 52 53 53 cluster * systemCluster; 54 processor* systemProcessor;54 system_proc_t * systemProcessor; 55 55 thread_desc * mainThread; 56 56 … … 81 81 82 82 void ?{}( current_stack_info_t * this ) { 83 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 1\n"); 83 84 CtxGet( &this->ctx ); 84 85 this->base = this->ctx.FP; … … 95 96 96 97 void ?{}( coStack_t * this, current_stack_info_t * info) { 98 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 2\n"); 97 99 this->size = info->size; 98 100 this->storage = info->storage; … … 105 107 106 108 void ?{}( coroutine_desc * this, current_stack_info_t * info) { 109 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 3\n"); 107 110 (&this->stack){ info }; 108 111 this->name = "Main Thread"; … … 112 115 113 116 void ?{}( thread_desc * this, current_stack_info_t * info) { 117 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 4\n"); 114 118 (&this->cor){ info }; 115 119 } … … 118 122 // Processor coroutine 119 123 void ?{}(processorCtx_t * this, processor * proc) { 120 (&this->__cor){}; 124 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 5\n"); 125 (&this->__cor){ "Processor" }; 121 126 this->proc = proc; 122 127 proc->runner = this; … … 124 129 125 130 void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) { 131 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 6\n"); 126 132 (&this->__cor){ info }; 127 133 this->proc = proc; … … 130 136 131 137 void ?{}(processor * this) { 138 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 7\n"); 132 139 this{ systemCluster }; 133 140 } 134 141 135 142 void ?{}(processor * this, cluster * cltr) { 143 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 8\n"); 136 144 this->cltr = cltr; 137 145 this->current_coroutine = NULL; … … 153 161 LIB_DEBUG_PRINT_SAFE("Kernel : constructing processor context %p\n", runner); 154 162 runner{ this }; 163 } 164 165 void ?{}(system_proc_t * this, cluster * cltr, processorCtx_t * runner) { 166 LIB_DEBUG_PRINT_SAFE("Kernel : Ctor 9\n"); 167 (&this->alarms){}; 168 (&this->alarm_lock){}; 169 170 (&this->proc){ cltr, runner }; 155 171 } 156 172 … … 316 332 assertf( thrd->next == NULL, "Expected null got %p", thrd->next ); 317 333 318 lock( &systemProcessor-> cltr->lock );319 append( &systemProcessor-> cltr->ready_queue, thrd );320 unlock( &systemProcessor-> cltr->lock );334 lock( &systemProcessor->proc.cltr->lock ); 335 append( &systemProcessor->proc.cltr->ready_queue, thrd ); 336 unlock( &systemProcessor->proc.cltr->lock ); 321 337 } 322 338 … … 367 383 } 368 384 385 //============================================================================================= 386 // Kernel Preemption logic 387 //============================================================================================= 388 389 #define __CFA_DEFAULT_PREEMPTION__ 10 390 391 unsigned int default_preemption() { 392 return __CFA_DEFAULT_PREEMPTION__; 393 } 394 395 void kernel_start_preemption() { 396 397 } 398 399 //============================================================================================= 400 // Kernel Setup logic 401 //============================================================================================= 369 402 //----------------------------------------------------------------------------- 370 403 // Kernel boot procedures … … 379 412 mainThread{ &info }; 380 413 414 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n"); 415 416 // Enable preemption 417 kernel_start_preemption(); 418 381 419 // Initialize the system cluster 382 420 systemCluster = (cluster *)&systemCluster_storage; 383 421 systemCluster{}; 384 422 423 LIB_DEBUG_PRINT_SAFE("Kernel : System cluster ready\n"); 424 385 425 // Initialize the system processor and the system processor ctx 386 426 // (the coroutine that contains the processing control flow) 387 systemProcessor = ( processor*)&systemProcessor_storage;427 systemProcessor = (system_proc_t *)&systemProcessor_storage; 388 428 systemProcessor{ systemCluster, (processorCtx_t *)&systemProcessorCtx_storage }; 389 429 390 430 // Add the main thread to the ready queue 391 // once resume is called on systemProcessor-> ctxthe mainThread needs to be scheduled like any normal thread431 // once resume is called on systemProcessor->runner the mainThread needs to be scheduled like any normal thread 392 432 ScheduleThread(mainThread); 393 433 394 434 //initialize the global state variables 395 this_processor = systemProcessor;435 this_processor = &systemProcessor->proc; 396 436 this_processor->current_thread = mainThread; 397 437 this_processor->current_coroutine = &mainThread->cor; … … 400 440 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 401 441 // mainThread is on the ready queue when this call is made. 402 resume( systemProcessor->runner);442 resume( systemProcessor->proc.runner ); 403 443 404 444 … … 414 454 // When its coroutine terminates, it return control to the mainThread 415 455 // which is currently here 416 systemProcessor-> is_terminated = true;456 systemProcessor->proc.is_terminated = true; 417 457 suspend(); 418 458 … … 421 461 // Destroy the system processor and its context in reverse order of construction 422 462 // These were manually constructed so we need manually destroy them 423 ^(systemProcessor-> runner){};463 ^(systemProcessor->proc.runner){}; 424 464 ^(systemProcessor){}; 425 465 … … 484 524 } 485 525 526 //============================================================================================= 527 // Kernel Utilities 528 //============================================================================================= 486 529 //----------------------------------------------------------------------------- 487 530 // Locks -
src/libcfa/concurrency/kernel_private.h
r2f9a722 rfa21ac9 21 21 #include "thread" 22 22 23 #include "alarm.h" 24 23 25 //----------------------------------------------------------------------------- 24 26 // Scheduler … … 35 37 //----------------------------------------------------------------------------- 36 38 // Processor 37 structprocessorCtx_t {39 coroutine processorCtx_t { 38 40 processor * proc; 39 coroutine_desc __cor;40 41 }; 41 42 DECL_COROUTINE(processorCtx_t);43 42 44 43 void main(processorCtx_t *); … … 47 46 void finishRunning(processor * this); 48 47 void spin(processor * this, unsigned int * spin_count); 48 49 struct system_proc_t { 50 processor proc; 51 52 alarm_list_t alarms; 53 spinlock alarm_lock; 54 }; 55 56 extern cluster * systemCluster; 57 extern system_proc_t * systemProcessor; 49 58 50 59 //-----------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.