Ignore:
File:
1 edited

Legend:

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

    rea8b2f7 r85b1deb  
    147147        runner.proc = &this;
    148148
    149         sem_init(&idleLock, 0, 0);
     149        idleLock{};
    150150
    151151        start( &this );
     
    155155        if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) {
    156156                __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
    157                 terminate(&this);
    158                 verify( __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
    159                 verify( kernelTLS.this_processor != &this);
     157
     158                __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED);
     159                wake( &this );
     160
    160161                P( terminated );
    161162                verify( kernelTLS.this_processor != &this);
    162                 pthread_join( kernel_thread, NULL );
    163         }
    164 
    165         sem_destroy(&idleLock);
     163        }
     164
     165        pthread_join( kernel_thread, NULL );
    166166}
    167167
     
    295295}
    296296
    297 // Handles spinning logic
    298 // TODO : find some strategy to put cores to sleep after some time
    299 void spin(processor * this, unsigned int * spin_count) {
    300         // (*spin_count)++;
    301         halt(this);
    302 }
    303 
    304297// KERNEL_ONLY
    305298// Context invoker for processors
     
    408401                unlock( ready_queue_lock );
    409402
    410                 if( was_empty ) {
     403                if(was_empty) {
    411404                        lock      (proc_list_lock __cfaabi_dbg_ctx2);
    412405                        if(idles) {
    413                                 wake(idles.head);
     406                                wake_fast(idles.head);
    414407                        }
    415408                        unlock    (proc_list_lock);
    416409                }
     410                else if( struct processor * idle = idles.head ) {
     411                        wake_fast(idle);
     412                }
     413
    417414        }
    418415
     
    660657
    661658void halt(processor * this) with( *this ) {
    662         verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
     659        // verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
    663660
    664661        with( *cltr ) {
     
    671668        __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this);
    672669
    673         // #ifdef __CFA_WITH_VERIFY__
    674         //      int sval = 0;
    675         //      sem_getvalue(&this->idleLock, &sval);
    676         //      verifyf(sval < 200, "Binary semaphore reached value %d : \n", sval);
    677         // #endif
    678 
    679         verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
    680         int __attribute__((unused)) ret = sem_wait(&idleLock);
    681         // verifyf(ret >= 0 || errno == EINTR, "Sem_wait returned %d (errno %d : %s\n", ret, errno, strerror(errno));
    682 
    683         // wait( idleLock );
     670        wait( idleLock );
    684671
    685672        __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this);
     
    691678                unlock    (proc_list_lock);
    692679        }
    693 }
    694 
    695 void wake(processor * this) {
    696         __cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this);
    697         int __attribute__((unused)) ret = sem_post(&this->idleLock);
    698         // verifyf(ret >= 0 || errno == EINTR, "Sem_post returned %d (errno %d : %s\n", ret, errno, strerror(errno));
    699 
    700         // #ifdef __CFA_WITH_VERIFY__
    701         //      int sval = 0;
    702         //      sem_getvalue(&this->idleLock, &sval);
    703         //      verifyf(sval < 200, "Binary semaphore reached value %d\n", sval);
    704         // #endif
    705 
    706         // post( this->idleLock );
    707680}
    708681
Note: See TracChangeset for help on using the changeset viewer.