Changeset dcb42b8 for src/libcfa
- Timestamp:
- Jan 19, 2017, 4:04:38 PM (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:
- bd98b58
- Parents:
- 8f49a54
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r8f49a54 rdcb42b8 230 230 // Start by initializing the main thread 231 231 mainThread = (thread_h *)&mainThread_storage; 232 LIB_DEBUG_PRINTF("Kernel : Main thread : %p\n", mainThread );233 232 mainThread{ &ctx }; 234 233 … … 242 241 systemProcessor->ctx{ systemProcessor }; 243 242 243 // Add the main thread to the ready queue 244 // once resume is called on systemProcessor->ctx the mainThread needs to be scheduled like any normal thread 244 245 scheduler_add(mainThread); 245 246 247 //initialize the global state variables 246 248 current_coroutine = &mainThread->c; 247 249 248 LIB_DEBUG_PRINTF("Kernel : Starting system processor\n"); 250 // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX 251 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 252 // mainThread is on the ready queue when this call is made. 249 253 resume(systemProcessor->ctx); 250 254 255 256 257 // THE SYSTEM IS NOW COMPLETELY RUNNING 258 259 260 251 261 LIB_DEBUG_PRINTF("Kernel : Started\n--------------------------------------------------\n\n"); 252 262 } 263 253 264 void kernel_shutdown(void) { 254 LIB_DEBUG_PRINTF("\n--------------------------------------------------\nKernel : Shutting down"); 255 256 LIB_DEBUG_PRINTF("Unscheduling main thread\n"); 257 scheduler_remove(mainThread); 258 259 LIB_DEBUG_PRINTF("Kernel : Terminating system processor\n"); 265 LIB_DEBUG_PRINTF("\n--------------------------------------------------\nKernel : Shutting down\n"); 266 267 // SKULLDUGGERY: Notify the systemProcessor it needs to terminates. 268 // When its coroutine terminates, it return control to the mainThread 269 // which is currently here 260 270 systemProcessor->terminated = true; 261 262 271 suspend(); 263 272 264 LIB_DEBUG_PRINTF("Kernel : Control returned to initial process thread\n"); 265 273 // THE SYSTEM IS NOW COMPLETELY STOPPED 274 275 // Destroy the system processor and its context in reverse order of construction 276 // These were manually constructed so we need manually destroy them 266 277 ^(systemProcessor->ctx){}; 267 278 ^(systemProcessor){}; 268 279 280 // Final step, destroy the main thread since it is no longer needed 281 // Since we provided a stack to this taxk it will not destroy anything 269 282 ^(mainThread){}; 270 283
Note: See TracChangeset
for help on using the changeset viewer.