Ignore:
Timestamp:
Nov 2, 2020, 12:44: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:
58688bf, 82f791f
Parents:
f7136f7
Message:

Removed unpark and added support for unpark from the kernel (removing the distinction between the two

File:
1 edited

Legend:

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

    rf7136f7 re873838  
    108108static $thread * __next_thread_slow(cluster * this);
    109109static void __run_thread(processor * this, $thread * dst);
    110 static void __wake_one(struct __processor_id_t * id, cluster * cltr);
     110static void __wake_one(cluster * cltr);
    111111
    112112static void push  (__cluster_idles & idles, processor & proc);
     
    282282                if(unlikely(thrd_dst->preempted != __NO_PREEMPTION)) {
    283283                        // The thread was preempted, reschedule it and reset the flag
    284                         __schedule_thread( (__processor_id_t*)this, thrd_dst );
     284                        __schedule_thread( thrd_dst );
    285285                        break RUNNING;
    286286                }
     
    358358// Scheduler routines
    359359// KERNEL ONLY
    360 void __schedule_thread( struct __processor_id_t * id, $thread * thrd ) {
     360void __schedule_thread( $thread * thrd ) {
    361361        /* paranoid */ verify( thrd );
    362362        /* paranoid */ verify( thrd->state != Halted );
    363363        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     364        /* paranoid */ verify( kernelTLS.this_proc_id );
    364365        /* paranoid */ #if defined( __CFA_WITH_VERIFY__ )
    365366        /* paranoid */  if( thrd->state == Blocked || thrd->state == Start ) assertf( thrd->preempted == __NO_PREEMPTION,
     
    374375        if (thrd->preempted == __NO_PREEMPTION) thrd->state = Ready;
    375376
    376         ready_schedule_lock  ( id );
     377        ready_schedule_lock();
    377378                push( thrd->curr_cluster, thrd );
    378                 __wake_one(id, thrd->curr_cluster);
    379         ready_schedule_unlock( id );
     379                __wake_one(thrd->curr_cluster);
     380        ready_schedule_unlock();
    380381
    381382        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     
    384385// KERNEL ONLY
    385386static inline $thread * __next_thread(cluster * this) with( *this ) {
    386         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    387 
    388         ready_schedule_lock  ( (__processor_id_t*)kernelTLS.this_processor );
     387        /* paranoid */ verify( kernelTLS.this_proc_id );
     388        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     389
     390        ready_schedule_lock();
    389391                $thread * thrd = pop( this );
    390         ready_schedule_unlock( (__processor_id_t*)kernelTLS.this_processor );
    391 
    392         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     392        ready_schedule_unlock();
     393
     394        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     395        /* paranoid */ verify( kernelTLS.this_proc_id );
    393396        return thrd;
    394397}
     
    396399// KERNEL ONLY
    397400static inline $thread * __next_thread_slow(cluster * this) with( *this ) {
    398         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    399 
    400         ready_schedule_lock  ( (__processor_id_t*)kernelTLS.this_processor );
     401        /* paranoid */ verify( kernelTLS.this_proc_id );
     402        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     403
     404        ready_schedule_lock();
    401405                $thread * thrd = pop_slow( this );
    402         ready_schedule_unlock( (__processor_id_t*)kernelTLS.this_processor );
    403 
    404         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     406        ready_schedule_unlock();
     407
     408        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     409        /* paranoid */ verify( kernelTLS.this_proc_id );
    405410        return thrd;
    406411}
    407412
    408 // KERNEL ONLY unpark with out disabling interrupts
    409 void __unpark(  struct __processor_id_t * id, $thread * thrd ) {
     413void unpark( $thread * thrd ) {
     414        if( !thrd ) return;
     415
     416        /* paranoid */ verify( kernelTLS.this_proc_id );
     417        bool full = kernelTLS.this_proc_id->full_proc;
     418        if(full) disable_interrupts();
     419
     420        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    410421        int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST);
    411422        switch(old_ticket) {
     
    418429
    419430                        // Wake lost the race,
    420                         __schedule_thread( id, thrd );
     431                        __schedule_thread( thrd );
    421432                        break;
    422433                default:
     
    424435                        abort("Thread %p (%s) has mismatch park/unpark\n", thrd, thrd->self_cor.name);
    425436        }
    426 }
    427 
    428 void unpark( $thread * thrd ) {
    429         if( !thrd ) return;
    430 
    431         disable_interrupts();
    432         __unpark( (__processor_id_t*)kernelTLS.this_processor, thrd );
    433         enable_interrupts( __cfaabi_dbg_ctx );
     437        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     438
     439        if(full) enable_interrupts( __cfaabi_dbg_ctx );
     440        /* paranoid */ verify( kernelTLS.this_proc_id );
    434441}
    435442
     
    505512//=============================================================================================
    506513// Wake a thread from the front if there are any
    507 static void __wake_one(struct __processor_id_t * id, cluster * this) {
    508         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    509         /* paranoid */ verify( ready_schedule_islocked( id ) );
     514static void __wake_one(cluster * this) {
     515        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     516        /* paranoid */ verify( ready_schedule_islocked() );
    510517
    511518        // Check if there is a sleeping processor
     
    525532        #endif
    526533
    527         /* paranoid */ verify( ready_schedule_islocked( id ) );
     534        /* paranoid */ verify( ready_schedule_islocked() );
    528535        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    529536
Note: See TracChangeset for help on using the changeset viewer.