Ignore:
File:
1 edited

Legend:

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

    rf32e53e r4aa2fb2  
    7272// Main thread construction
    7373struct current_stack_info_t {
    74         machine_context_t ctx;
     74        machine_context_t ctx; 
    7575        unsigned int size;              // size of stack
    7676        void *base;                             // base of stack
     
    8282
    8383void ?{}( current_stack_info_t * this ) {
    84         CtxGet( this->ctx );
     84        CtxGet( &this->ctx );
    8585        this->base = this->ctx.FP;
    8686        this->storage = this->ctx.SP;
     
    106106
    107107void ?{}( coroutine_desc * this, current_stack_info_t * info) {
    108         (&this->stack){ info };
     108        (&this->stack){ info }; 
    109109        this->name = "Main Thread";
    110110        this->errno_ = 0;
     
    184184
    185185void ^?{}(cluster * this) {
    186 
     186       
    187187}
    188188
     
    203203
    204204                thread_desc * readyThread = NULL;
    205                 for( unsigned int spin_count = 0; ! this->is_terminated; spin_count++ )
     205                for( unsigned int spin_count = 0; ! this->is_terminated; spin_count++ ) 
    206206                {
    207207                        readyThread = nextThread( this->cltr );
     
    229229}
    230230
    231 // runThread runs a thread by context switching
    232 // from the processor coroutine to the target thread
     231// runThread runs a thread by context switching 
     232// from the processor coroutine to the target thread 
    233233void runThread(processor * this, thread_desc * dst) {
    234234        coroutine_desc * proc_cor = get_coroutine(this->runner);
    235235        coroutine_desc * thrd_cor = get_coroutine(dst);
    236 
     236       
    237237        //Reset the terminating actions here
    238238        this->finish.action_code = No_Action;
     
    246246}
    247247
    248 // Once a thread has finished running, some of
     248// Once a thread has finished running, some of 
    249249// its final actions must be executed from the kernel
    250250void finishRunning(processor * this) {
     
    256256        }
    257257        else if( this->finish.action_code == Release_Schedule ) {
    258                 unlock( this->finish.lock );
     258                unlock( this->finish.lock );           
    259259                ScheduleThread( this->finish.thrd );
    260260        }
     
    291291        // SKULLDUGGERY: We want to create a context for the processor coroutine
    292292        // which is needed for the 2-step context switch. However, there is no reason
    293         // to waste the perfectly valid stack create by pthread.
     293        // to waste the perfectly valid stack create by pthread. 
    294294        current_stack_info_t info;
    295295        machine_context_t ctx;
     
    306306        LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
    307307
    308         // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't
    309         // resume it to start it like it normally would, it will just context switch
    310         // back to here. Instead directly call the main since we already are on the
     308        // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't 
     309        // resume it to start it like it normally would, it will just context switch 
     310        // back to here. Instead directly call the main since we already are on the 
    311311        // appropriate stack.
    312312        proc_cor_storage.__cor.state = Active;
     
    315315
    316316        // Main routine of the core returned, the core is now fully terminated
    317         LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner);
     317        LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner); 
    318318
    319319        return NULL;
     
    322322void start(processor * this) {
    323323        LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);
    324 
     324       
    325325        pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
    326326
    327         LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);
     327        LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);       
    328328}
    329329
     
    334334
    335335        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    336 
     336       
    337337        lock( &systemProcessor->proc.cltr->lock );
    338338        append( &systemProcessor->proc.cltr->ready_queue, thrd );
     
    392392// Kernel boot procedures
    393393void kernel_startup(void) {
    394         LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");
     394        LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");   
    395395
    396396        // Start by initializing the main thread
    397         // SKULLDUGGERY: the mainThread steals the process main thread
     397        // SKULLDUGGERY: the mainThread steals the process main thread 
    398398        // which will then be scheduled by the systemProcessor normally
    399399        mainThread = (thread_desc *)&mainThread_storage;
     
    417417        systemProcessor{ systemCluster, (processorCtx_t *)&systemProcessorCtx_storage };
    418418
    419         // Add the main thread to the ready queue
     419        // Add the main thread to the ready queue 
    420420        // once resume is called on systemProcessor->runner the mainThread needs to be scheduled like any normal thread
    421421        ScheduleThread(mainThread);
     
    428428        // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX
    429429        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    430         // mainThread is on the ready queue when this call is made.
     430        // mainThread is on the ready queue when this call is made. 
    431431        resume( systemProcessor->proc.runner );
    432432
     
    457457        ^(mainThread){};
    458458
    459         LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");
     459        LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");   
    460460}
    461461
     
    473473                kernel_abort_called = true;
    474474                unlock( &kernel_abort_lock );
    475         }
     475        } 
    476476        else {
    477477                unlock( &kernel_abort_lock );
    478 
     478               
    479479                sigset_t mask;
    480480                sigemptyset( &mask );
     
    482482                sigaddset( &mask, SIGUSR1 );                    // block SIGUSR1 signals
    483483                sigsuspend( &mask );                            // block the processor to prevent further damage during abort
    484                 _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it
     484                _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it             
    485485        }
    486486
     
    497497                len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine()->name, this_coroutine() );
    498498                __lib_debug_write( STDERR_FILENO, abort_text, len );
    499         }
     499        } 
    500500        else {
    501501                __lib_debug_write( STDERR_FILENO, ".\n", 2 );
     
    590590                }
    591591                head->next = NULL;
    592         }
     592        }       
    593593        return head;
    594594}
     
    609609                this->top = top->next;
    610610                top->next = NULL;
    611         }
     611        }       
    612612        return top;
    613613}
Note: See TracChangeset for help on using the changeset viewer.