Changeset 5ece8ce for libcfa/src


Ignore:
Timestamp:
May 24, 2023, 11:45:39 AM (12 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
88b49bb
Parents:
76e77a4
Message:

fixed a bug in mcs implementation and cleaned up a bit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/locks.hfa

    r76e77a4 r5ece8ce  
    176176static inline void ?{}(mcs_spin_node & this) { this.next = 0p; this.locked = true; }
    177177
    178 static inline mcs_spin_node * volatile & ?`next ( mcs_spin_node * node ) {
    179         return node->next;
    180 }
    181 
    182178struct mcs_spin_lock {
    183179        mcs_spin_queue queue;
     
    185181
    186182static inline void lock(mcs_spin_lock & l, mcs_spin_node & n) {
     183    n.locked = true;
    187184        mcs_spin_node * prev = __atomic_exchange_n(&l.queue.tail, &n, __ATOMIC_SEQ_CST);
    188         n.locked = true;
    189         if(prev == 0p) return;
     185        if( prev == 0p ) return;
    190186        prev->next = &n;
    191         while(__atomic_load_n(&n.locked, __ATOMIC_RELAXED)) Pause();
     187        while( __atomic_load_n(&n.locked, __ATOMIC_RELAXED) ) Pause();
    192188}
    193189
     
    195191        mcs_spin_node * n_ptr = &n;
    196192        if (__atomic_compare_exchange_n(&l.queue.tail, &n_ptr, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) return;
    197         while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) {}
     193        while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) Pause();
    198194        n.next->locked = false;
    199195}
Note: See TracChangeset for help on using the changeset viewer.