Changeset 9e3d123
- Timestamp:
- Jun 16, 2022, 2:39:28 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 76a798d
- Parents:
- e1a9c77
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
re1a9c77 r9e3d123 126 126 static inline void lock(mcs_spin_lock & l, mcs_spin_node & n) { 127 127 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(); 132 131 } 133 132 134 133 static inline void unlock(mcs_spin_lock & l, mcs_spin_node & n) { 135 134 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; 140 138 } 141 139
Note: See TracChangeset
for help on using the changeset viewer.