Changeset 5f5a729


Ignore:
Timestamp:
Nov 17, 2021, 11:17:59 AM (7 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
enum, forall-pointer-decay, master
Children:
84a6e70
Parents:
1387ea0
Message:

Mark idle now uses try_lock semantics

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

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

    r1387ea0 r5f5a729  
    124124static void __wake_one(cluster * cltr);
    125125
    126 static void mark_idle (__cluster_proc_list & idles, processor & proc);
     126static bool mark_idle (__cluster_proc_list & idles, processor & proc);
    127127static void mark_awake(__cluster_proc_list & idles, processor & proc);
    128128static [unsigned idle, unsigned total, * processor] query_idles( & __cluster_proc_list idles );
     
    213213
    214214                                // Push self to idle stack
    215                                 mark_idle(this->cltr->procs, * this);
     215                                if(!mark_idle(this->cltr->procs, * this)) continue MAIN_LOOP;
    216216
    217217                                // Confirm the ready-queue is empty
     
    331331                                // Push self to idle stack
    332332                                ready_schedule_unlock();
    333                                 mark_idle(this->cltr->procs, * this);
     333                                if(!mark_idle(this->cltr->procs, * this)) goto SEARCH;
    334334                                ready_schedule_lock();
    335335
     
    806806}
    807807
    808 static void mark_idle(__cluster_proc_list & this, processor & proc) {
    809         /* paranoid */ verify( ! __preemption_enabled() );
    810         lock( this );
     808static bool mark_idle(__cluster_proc_list & this, processor & proc) {
     809        /* paranoid */ verify( ! __preemption_enabled() );
     810        if(!try_lock( this )) return false;
    811811                this.idle++;
    812812                /* paranoid */ verify( this.idle <= this.total );
     
    815815        unlock( this );
    816816        /* paranoid */ verify( ! __preemption_enabled() );
     817
     818        return true;
    817819}
    818820
  • libcfa/src/concurrency/kernel_private.hfa

    r1387ea0 r5f5a729  
    282282}
    283283
     284static inline bool try_lock(__cluster_proc_list & this) {
     285        /* paranoid */ verify( ! __preemption_enabled() );
     286
     287        // Start by locking the global RWlock so that we know no-one is
     288        // adding/removing processors while we mess with the idle lock
     289        ready_schedule_lock();
     290
     291        // Simple counting lock, acquired, acquired by incrementing the counter
     292        // to an odd number
     293        uint64_t l = this.lock;
     294        if(
     295                (0 == (l % 2))
     296                && __atomic_compare_exchange_n(&this.lock, &l, l + 1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
     297        ) {
     298                // success
     299                /* paranoid */ verify( ! __preemption_enabled() );
     300                return true;
     301        }
     302
     303        // failed to lock
     304        ready_schedule_unlock();
     305
     306        /* paranoid */ verify( ! __preemption_enabled() );
     307        return false;
     308}
     309
    284310static inline void unlock(__cluster_proc_list & this) {
    285311        /* paranoid */ verify( ! __preemption_enabled() );
Note: See TracChangeset for help on using the changeset viewer.