Ignore:
Timestamp:
May 12, 2020, 1:32:45 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
4fa44e7
Parents:
6a490b2
Message:

Some fixes after the merge, compiles but still has livelocks

File:
1 edited

Legend:

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

    r6a490b2 r504a7dc  
    120120static void __run_thread(processor * this, $thread * dst);
    121121static $thread * __halt(processor * this);
    122 static bool __wake_one(cluster * cltr, bool was_empty);
     122static bool __wake_one(cluster * cltr);
    123123static bool __wake_proc(processor *);
    124124
     
    299299        // register the processor unless it's the main thread which is handled in the boot sequence
    300300        if(this != mainProcessor) {
    301                 this->id = doregister(this->cltr, this);
     301                this->id = doregister2(this->cltr, this);
    302302                ready_queue_grow( this->cltr );
    303303        }
    304304
     305        doregister(this->cltr, this);
    305306
    306307        {
     
    325326                                /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    326327                                /* paranoid */ verifyf( readyThread->state == Ready || readyThread->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", readyThread->state, readyThread->preempted);
    327                                 /* paranoid */ verifyf( readyThread->next == 0p, "Expected null got %p", readyThread->next );
     328                                /* paranoid */ verifyf( readyThread->link.next == 0p, "Expected null got %p", readyThread->link.next );
    328329
    329330                                // We found a thread run it
     
    337338        }
    338339
     340        unregister(this->cltr, this);
     341
    339342        V( this->terminated );
    340343
     
    342345        if(this != mainProcessor) {
    343346                ready_queue_shrink( this->cltr );
    344                 unregister(this->cltr, this);
     347                unregister2(this->cltr, this);
    345348        }
    346349        else {
     
    610613        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    611614        /* paranoid */ #if defined( __CFA_WITH_VERIFY__ )
    612         /* paranoid */ if( thrd->state == Blocked || thrd->state == Start ) assertf( thrd->preempted == __NO_PREEMPTION,
    613                           "Error inactive thread marked as preempted, state %d, preemption %d\n", thrd->state, thrd->preempted );
    614         /* paranoid */ if( thrd->preempted != __NO_PREEMPTION ) assertf(thrd->state == Active || thrd->state == Rerun,
    615                           "Error preempted thread marked as not currently running, state %d, preemption %d\n", thrd->state, thrd->preempted );
     615        /* paranoid */  if( thrd->state == Blocked || thrd->state == Start ) assertf( thrd->preempted == __NO_PREEMPTION,
     616                                        "Error inactive thread marked as preempted, state %d, preemption %d\n", thrd->state, thrd->preempted );
     617        /* paranoid */  if( thrd->preempted != __NO_PREEMPTION ) assertf(thrd->state == Active || thrd->state == Rerun,
     618                                        "Error preempted thread marked as not currently running, state %d, preemption %d\n", thrd->state, thrd->preempted );
    616619        /* paranoid */ #endif
    617620        /* paranoid */ verifyf( thrd->link.next == 0p, "Expected null got %p", thrd->link.next );
     
    620623
    621624        ready_schedule_lock(thrd->curr_cluster, kernelTLS.this_processor);
    622                 bool was_empty = push( thrd->curr_cluster, thrd );
     625                push( thrd->curr_cluster, thrd );
     626
     627                __wake_one(thrd->curr_cluster);
    623628        ready_schedule_unlock(thrd->curr_cluster, kernelTLS.this_processor);
    624 
    625         __wake_one(thrd->curr_cluster, was_empty);
    626629
    627630        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     
    718721        // If that is the case, abandon the preemption.
    719722        bool preempted = false;
    720         if(thrd->next == 0p) {
     723        if(thrd->link.next == 0p) {
    721724                preempted = true;
    722725                thrd->preempted = reason;
     
    789792        (*mainProcessor){};
    790793
    791         mainProcessor->id = doregister(mainCluster, mainProcessor);
     794        mainProcessor->id = doregister2(mainCluster, mainProcessor);
    792795
    793796        //initialize the global state variables
     
    844847        kernel_stop_preemption();
    845848
    846         unregister(mainCluster, mainProcessor);
     849        unregister2(mainCluster, mainProcessor);
    847850
    848851        // Destroy the main processor and its context in reverse order of construction
     
    909912
    910913// Wake a thread from the front if there are any
    911 static bool __wake_one(cluster * this, __attribute__((unused)) bool force) {
    912         // if we don't want to force check if we know it's false
    913         // if( !this->idles.head && !force ) return false;
    914 
     914static bool __wake_one(cluster * this) {
    915915        // First, lock the cluster idle
    916916        lock( this->idle_lock __cfaabi_dbg_ctx2 );
     
    10991099        cltr->nthreads -= 1;
    11001100        unlock(cltr->thread_list_lock);
     1101}
     1102
     1103void doregister( cluster * cltr, processor * proc ) {
     1104        lock      (cltr->idle_lock __cfaabi_dbg_ctx2);
     1105        cltr->nprocessors += 1;
     1106        push_front(cltr->procs, *proc);
     1107        unlock    (cltr->idle_lock);
     1108}
     1109
     1110void unregister( cluster * cltr, processor * proc ) {
     1111        lock  (cltr->idle_lock __cfaabi_dbg_ctx2);
     1112        remove(cltr->procs, *proc );
     1113        cltr->nprocessors -= 1;
     1114        unlock(cltr->idle_lock);
    11011115}
    11021116
Note: See TracChangeset for help on using the changeset viewer.