Changeset dcb42b8 for src/libcfa


Ignore:
Timestamp:
Jan 19, 2017, 4:04:38 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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
Message:

Some more cleaning and commenting the kernel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel.c

    r8f49a54 rdcb42b8  
    230230        // Start by initializing the main thread
    231231        mainThread = (thread_h *)&mainThread_storage;
    232         LIB_DEBUG_PRINTF("Kernel : Main thread : %p\n", mainThread );
    233232        mainThread{ &ctx };
    234233
     
    242241        systemProcessor->ctx{ systemProcessor };
    243242
     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
    244245        scheduler_add(mainThread);
    245246
     247        //initialize the global state variables
    246248        current_coroutine = &mainThread->c;
    247249
    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.
    249253        resume(systemProcessor->ctx);
    250254
     255
     256
     257        // THE SYSTEM IS NOW COMPLETELY RUNNING
     258
     259
     260
    251261        LIB_DEBUG_PRINTF("Kernel : Started\n--------------------------------------------------\n\n");
    252262}
     263
    253264void 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
    260270        systemProcessor->terminated = true;
    261 
    262271        suspend();
    263272
    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
    266277        ^(systemProcessor->ctx){};
    267278        ^(systemProcessor){};
    268279
     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
    269282        ^(mainThread){};
    270283
Note: See TracChangeset for help on using the changeset viewer.