Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/startup.cfa

    rd874f59 r7dd98b6  
    100100// Other Forward Declarations
    101101extern void __wake_proc(processor *);
     102extern int cfa_main_returned;                                                   // from interpose.cfa
    102103
    103104//-----------------------------------------------------------------------------
     
    200201        __cfadbg_print_safe(runtime_core, "Kernel : Main cluster ready\n");
    201202
     203        // Construct the processor context of the main processor
     204        void ?{}(processorCtx_t & this, processor * proc) {
     205                (this.__cor){ "Processor" };
     206                this.__cor.starter = 0p;
     207                this.proc = proc;
     208        }
     209
     210        void ?{}(processor & this) with( this ) {
     211                ( this.terminated ){};
     212                ( this.runner ){};
     213                init( this, "Main Processor", *mainCluster, 0p );
     214                kernel_thread = pthread_self();
     215
     216                runner{ &this };
     217                __cfadbg_print_safe(runtime_core, "Kernel : constructed main processor context %p\n", &runner);
     218        }
     219
     220        // Initialize the main processor and the main processor ctx
     221        // (the coroutine that contains the processing control flow)
     222        mainProcessor = (processor *)&storage_mainProcessor;
     223        (*mainProcessor){};
     224
     225        register_tls( mainProcessor );
     226
    202227        // Start by initializing the main thread
    203228        // SKULLDUGGERY: the mainThread steals the process main thread
     
    210235        __cfadbg_print_safe(runtime_core, "Kernel : Main thread ready\n");
    211236
    212 
    213 
    214         // Construct the processor context of the main processor
    215         void ?{}(processorCtx_t & this, processor * proc) {
    216                 (this.__cor){ "Processor" };
    217                 this.__cor.starter = 0p;
    218                 this.proc = proc;
    219         }
    220 
    221         void ?{}(processor & this) with( this ) {
    222                 ( this.terminated ){};
    223                 ( this.runner ){};
    224                 init( this, "Main Processor", *mainCluster, 0p );
    225                 kernel_thread = pthread_self();
    226 
    227                 runner{ &this };
    228                 __cfadbg_print_safe(runtime_core, "Kernel : constructed main processor context %p\n", &runner);
    229         }
    230 
    231         // Initialize the main processor and the main processor ctx
    232         // (the coroutine that contains the processing control flow)
    233         mainProcessor = (processor *)&storage_mainProcessor;
    234         (*mainProcessor){};
    235 
    236         register_tls( mainProcessor );
    237         mainThread->last_cpu = __kernel_getcpu();
    238 
    239237        //initialize the global state variables
    240238        __cfaabi_tls.this_processor = mainProcessor;
     
    252250        // Add the main thread to the ready queue
    253251        // once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread
    254         schedule_thread$(mainThread);
     252        schedule_thread$(mainThread, UNPARK_LOCAL);
    255253
    256254        // SKULLDUGGERY: Force a context switch to the main processor to set the main thread's context to the current UNIX
     
    271269
    272270static void __kernel_shutdown(void) {
     271        if(!cfa_main_returned) return;
    273272        /* paranoid */ verify( __preemption_enabled() );
    274273        disable_interrupts();
     
    486485        link.next = 0p;
    487486        link.ts   = -1llu;
    488         preferred = -1u;
     487        preferred = ready_queue_new_preferred();
    489488        last_proc = 0p;
    490489        #if defined( __CFA_WITH_VERIFY__ )
Note: See TracChangeset for help on using the changeset viewer.