Changeset 9e3d123


Ignore:
Timestamp:
Jun 16, 2022, 2:39:28 PM (2 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
76a798d
Parents:
e1a9c77
Message:

added atomic_load_n to mcs_spin in attempt at fixing it

File:
1 edited

Legend:

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

    re1a9c77 r9e3d123  
    126126static inline void lock(mcs_spin_lock & l, mcs_spin_node & n) {
    127127        mcs_spin_node * prev = __atomic_exchange_n(&l.queue.tail, &n, __ATOMIC_SEQ_CST);
    128         if(prev != 0p) {
    129                 prev->next = &n;
    130                 while(n.locked) Pause();
    131         }
     128        if(prev == 0p) return;
     129        prev->next = &n;
     130        while(__atomic_load_n(&n.locked, __ATOMIC_SEQ_CST)) Pause();
    132131}
    133132
    134133static inline void unlock(mcs_spin_lock & l, mcs_spin_node & n) {
    135134        mcs_spin_node * n_ptr = &n;
    136         if (!__atomic_compare_exchange_n(&l.queue.tail, &n_ptr, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ) {
    137                 while (n.next == 0p) {}
    138                 n.next->locked = false;
    139         }
     135        if (__atomic_compare_exchange_n(&l.queue.tail, &n_ptr, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) return;
     136        while (__atomic_load_n(&n.next, __ATOMIC_SEQ_CST) == 0p) {}
     137        n.next->locked = false;
    140138}
    141139
Note: See TracChangeset for help on using the changeset viewer.