Changeset c6c7e6c for libcfa/src


Ignore:
Timestamp:
Apr 24, 2021, 6:35:43 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
a3821fa
Parents:
c1c95b1
Message:

Seperated semphore and scheduling logic in unpark

File:
1 edited

Legend:

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

    rc1c95b1 rc6c7e6c  
    110110static $thread * __next_thread(cluster * this);
    111111static $thread * __next_thread_slow(cluster * this);
     112static inline bool __must_unpark( $thread * thrd ) __attribute((nonnull(1)));
    112113static void __run_thread(processor * this, $thread * dst);
    113114static void __wake_one(cluster * cltr);
     
    496497}
    497498
    498 void unpark( $thread * thrd ) {
    499         if( !thrd ) return;
    500 
     499static inline bool __must_unpark( $thread * thrd ) {
    501500        int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST);
    502501        switch(old_ticket) {
    503502                case TICKET_RUNNING:
    504503                        // Wake won the race, the thread will reschedule/rerun itself
    505                         break;
     504                        return false;
    506505                case TICKET_BLOCKED:
    507506                        /* paranoid */ verify( ! thrd->preempted != __NO_PREEMPTION );
    508507                        /* paranoid */ verify( thrd->state == Blocked );
    509 
    510                         {
    511                                 /* paranoid */ verify( publicTLS_get(this_proc_id) );
    512                                 disable_interrupts();
    513 
    514                                 /* paranoid */ verify( ! __preemption_enabled() );
    515 
    516                                 // Wake lost the race,
    517                                 __schedule_thread( thrd );
    518 
    519                                 /* paranoid */ verify( ! __preemption_enabled() );
    520 
    521                                 enable_interrupts_noPoll();
    522                                 /* paranoid */ verify( publicTLS_get(this_proc_id) );
    523                         }
    524 
    525                         break;
     508                        return true;
    526509                default:
    527510                        // This makes no sense, something is wrong abort
    528511                        abort("Thread %p (%s) has mismatch park/unpark\n", thrd, thrd->self_cor.name);
     512        }
     513}
     514
     515void unpark( $thread * thrd ) {
     516        if( !thrd ) return;
     517
     518        if(__must_unpark(thrd)) {
     519                /* paranoid */ verify( publicTLS_get(this_proc_id) );
     520                disable_interrupts();
     521
     522                /* paranoid */ verify( ! __preemption_enabled() );
     523
     524                // Wake lost the race,
     525                __schedule_thread( thrd );
     526
     527                /* paranoid */ verify( ! __preemption_enabled() );
     528
     529                enable_interrupts_noPoll();
     530                /* paranoid */ verify( publicTLS_get(this_proc_id) );
    529531        }
    530532}
Note: See TracChangeset for help on using the changeset viewer.