Ignore:
Timestamp:
Jun 7, 2018, 3:03:10 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, with_gc
Children:
61accc5
Parents:
61d9b4b (diff), a43c561 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

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

    r61d9b4b rc2b10fa  
    1717#include <stddef.h>
    1818#include <errno.h>
     19#include <string.h>
    1920extern "C" {
    2021#include <stdio.h>
     
    5051thread_desc * mainThread;
    5152
    52 struct { __dllist_t(cluster) list; __spinlock_t lock; } global_clusters;
     53extern "C" {
     54struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters;
     55}
    5356
    5457//-----------------------------------------------------------------------------
     
    150153
    151154void ^?{}(processor & this) with( this ){
    152         if( ! do_terminate ) {
     155        if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) {
    153156                __cfaabi_dbg_print_safe("Kernel : core %p signaling termination\n", &this);
    154157                terminate(&this);
    155                 verify(this.do_terminate);
     158                verify( __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
    156159                verify( kernelTLS.this_processor != &this);
    157160                P( terminated );
     
    199202
    200203                thread_desc * readyThread = NULL;
    201                 for( unsigned int spin_count = 0; ! this->do_terminate; spin_count++ )
     204                for( unsigned int spin_count = 0; ! __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST); spin_count++ )
    202205                {
    203206                        readyThread = nextThread( this->cltr );
     
    218221                        else
    219222                        {
    220                                 spin(this, &spin_count);
     223                                // spin(this, &spin_count);
     224                                halt(this);
    221225                        }
    222226                }
     
    545549        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    546550
    547         global_clusters.list{ __get };
    548         global_clusters.lock{};
     551        __cfa_dbg_global_clusters.list{ __get };
     552        __cfa_dbg_global_clusters.lock{};
    549553
    550554        // Initialize the main cluster
     
    627631        // When its coroutine terminates, it return control to the mainThread
    628632        // which is currently here
    629         mainProcessor->do_terminate = true;
     633        __atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE);
    630634        returnToKernel();
     635        mainThread->self_cor.state = Halted;
    631636
    632637        // THE SYSTEM IS NOW COMPLETELY STOPPED
     
    644649        ^(mainThread){};
    645650
    646         ^(global_clusters.list){};
    647         ^(global_clusters.lock){};
     651        ^(__cfa_dbg_global_clusters.list){};
     652        ^(__cfa_dbg_global_clusters.lock){};
    648653
    649654        __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
     
    655660
    656661void halt(processor * this) with( *this ) {
     662        verify( ! __atomic_load_n(&do_terminate, __ATOMIC_SEQ_CST) );
     663
    657664        with( *cltr ) {
    658665                lock      (proc_list_lock __cfaabi_dbg_ctx2);
     
    664671        __cfaabi_dbg_print_safe("Kernel : Processor %p ready to sleep\n", this);
    665672
    666         verify( ({int sval = 0; sem_getvalue(&this->idleLock, &sval); sval; }) < 200);
     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) );
    667680        int __attribute__((unused)) ret = sem_wait(&idleLock);
    668         verify(ret > 0 || errno == EINTR);
     681        // verifyf(ret >= 0 || errno == EINTR, "Sem_wait returned %d (errno %d : %s\n", ret, errno, strerror(errno));
     682
     683        // wait( idleLock );
    669684
    670685        __cfaabi_dbg_print_safe("Kernel : Processor %p woke up and ready to run\n", this);
     
    681696        __cfaabi_dbg_print_safe("Kernel : Waking up processor %p\n", this);
    682697        int __attribute__((unused)) ret = sem_post(&this->idleLock);
    683         verify(ret > 0 || errno == EINTR);
    684         verify( ({int sval = 0; sem_getvalue(&this->idleLock, &sval); sval; }) < 200);
     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 );
    685707}
    686708
     
    798820// Global Queues
    799821void doregister( cluster     & cltr ) {
    800         lock      ( global_clusters.lock __cfaabi_dbg_ctx2);
    801         push_front( global_clusters.list, cltr );
    802         unlock    ( global_clusters.lock );
     822        lock      ( __cfa_dbg_global_clusters.lock __cfaabi_dbg_ctx2);
     823        push_front( __cfa_dbg_global_clusters.list, cltr );
     824        unlock    ( __cfa_dbg_global_clusters.lock );
    803825}
    804826
    805827void unregister( cluster     & cltr ) {
    806         lock  ( global_clusters.lock __cfaabi_dbg_ctx2);
    807         remove( global_clusters.list, cltr );
    808         unlock( global_clusters.lock );
     828        lock  ( __cfa_dbg_global_clusters.lock __cfaabi_dbg_ctx2);
     829        remove( __cfa_dbg_global_clusters.list, cltr );
     830        unlock( __cfa_dbg_global_clusters.lock );
    809831}
    810832
Note: See TracChangeset for help on using the changeset viewer.