Ignore:
File:
1 edited

Legend:

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

    r82ff5845 rc81ebf9  
    154154        (&this->terminated){};
    155155        this->is_terminated = false;
    156         this->preemption_alarm = NULL;
    157         this->preemption = default_preemption();
    158         this->disable_preempt_count = 1;
     156        this->disable_preempt_count = 0;
    159157        this->pending_preemption = false;
    160         this->kernel_thread = pthread_self();
    161158
    162159        this->runner = runner;
    163         LIB_DEBUG_PRINT_SAFE("Kernel : constructing system processor context %p\n", runner);
     160        LIB_DEBUG_PRINT_SAFE("Kernel : constructing processor context %p\n", runner);
    164161        runner{ this };
    165162}
     
    243240        //Update global state
    244241        this->current_thread = dst;
    245 
    246         LIB_DEBUG_PRINT_SAFE("Kernel : running %p\n", dst);
    247242
    248243        // Context Switch to the thread
     
    327322void start(processor * this) {
    328323        LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);
    329 
    330         // SIGALRM must only be caught by the system processor
    331         sigset_t old_mask;
    332         bool is_system_proc = this_processor == &systemProcessor->proc;
    333         if ( is_system_proc ) {
    334                 // Child kernel-thread inherits the signal mask from the parent kernel-thread. So one special case for the
    335                 // system processor creating the user processor => toggle the blocking SIGALRM on system processor, create user
    336                 // processor, and toggle back (below) previous signal mask of the system processor.
    337 
    338                 sigset_t new_mask;
    339                 sigemptyset( &new_mask );
    340                 sigemptyset( &old_mask );
    341                 sigaddset( &new_mask, SIGALRM );
    342 
    343                 if ( sigprocmask( SIG_BLOCK, &new_mask, &old_mask ) == -1 ) {
    344                         abortf( "internal error, sigprocmask" );
    345                 }
    346 
    347                 assert( ! sigismember( &old_mask, SIGALRM ) );
    348         }
    349 
     324       
    350325        pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
    351 
    352         // Toggle back previous signal mask of system processor.
    353         if ( is_system_proc ) {
    354                 if ( sigprocmask( SIG_SETMASK, &old_mask, NULL ) == -1 ) {
    355                         abortf( "internal error, sigprocmask" );
    356                 } // if
    357         } // if
    358326
    359327        LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);       
     
    379347}
    380348
    381 void BlockInternal() {
    382         disable_interrupts();
     349void ScheduleInternal() {
    383350        suspend();
    384         enable_interrupts();
    385 }
    386 
    387 void BlockInternal( spinlock * lock ) {
    388         disable_interrupts();
     351}
     352
     353void ScheduleInternal( spinlock * lock ) {
    389354        this_processor->finish.action_code = Release;
    390355        this_processor->finish.lock = lock;
    391356        suspend();
    392         enable_interrupts();
    393 }
    394 
    395 void BlockInternal( thread_desc * thrd ) {
    396         disable_interrupts();
     357}
     358
     359void ScheduleInternal( thread_desc * thrd ) {
    397360        this_processor->finish.action_code = Schedule;
    398361        this_processor->finish.thrd = thrd;
    399362        suspend();
    400         enable_interrupts();
    401 }
    402 
    403 void BlockInternal( spinlock * lock, thread_desc * thrd ) {
    404         disable_interrupts();
     363}
     364
     365void ScheduleInternal( spinlock * lock, thread_desc * thrd ) {
    405366        this_processor->finish.action_code = Release_Schedule;
    406367        this_processor->finish.lock = lock;
    407368        this_processor->finish.thrd = thrd;
    408369        suspend();
    409         enable_interrupts();
    410 }
    411 
    412 void BlockInternal(spinlock ** locks, unsigned short count) {
    413         disable_interrupts();
     370}
     371
     372void ScheduleInternal(spinlock ** locks, unsigned short count) {
    414373        this_processor->finish.action_code = Release_Multi;
    415374        this_processor->finish.locks = locks;
    416375        this_processor->finish.lock_count = count;
    417376        suspend();
    418         enable_interrupts();
    419 }
    420 
    421 void BlockInternal(spinlock ** locks, unsigned short lock_count, thread_desc ** thrds, unsigned short thrd_count) {
    422         disable_interrupts();
     377}
     378
     379void ScheduleInternal(spinlock ** locks, unsigned short lock_count, thread_desc ** thrds, unsigned short thrd_count) {
    423380        this_processor->finish.action_code = Release_Multi_Schedule;
    424381        this_processor->finish.locks = locks;
     
    427384        this_processor->finish.thrd_count = thrd_count;
    428385        suspend();
    429         enable_interrupts();
    430386}
    431387
     
    447403        LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n");
    448404
     405        // Enable preemption
     406        kernel_start_preemption();
     407
    449408        // Initialize the system cluster
    450409        systemCluster = (cluster *)&systemCluster_storage;
     
    467426        this_processor->current_coroutine = &mainThread->cor;
    468427
    469         // Enable preemption
    470         kernel_start_preemption();
    471 
    472428        // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX
    473429        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
     
    479435        // THE SYSTEM IS NOW COMPLETELY RUNNING
    480436        LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n");
    481 
    482         enable_interrupts();
    483437}
    484438
     
    493447
    494448        // THE SYSTEM IS NOW COMPLETELY STOPPED
    495 
    496         // Disable preemption
    497         kernel_stop_preemption();
    498449
    499450        // Destroy the system processor and its context in reverse order of construction
     
    599550        if( !this->cond ) {
    600551                append( &this->blocked, this_thread() );
    601                 BlockInternal( &this->lock );
     552                ScheduleInternal( &this->lock );
    602553                lock( &this->lock );
    603554        }
Note: See TracChangeset for help on using the changeset viewer.