aboutsummaryrefslogtreecommitdiffstats
path: root/common/atomic.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-19 01:20:03 -0800
committerChris Robinson <[email protected]>2018-11-19 01:20:03 -0800
commit6e114a7a70c90d575e5978c5bcac95307bec0140 (patch)
tree82126cd9d68bf76de7e049dc5dbfc216a1b1f9b6 /common/atomic.h
parent190de1452e647aa9d45099d782d20473cba1284c (diff)
Replace ATOMIC_REPLACE_HEAD with an inline function
Diffstat (limited to 'common/atomic.h')
-rw-r--r--common/atomic.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/common/atomic.h b/common/atomic.h
index dbb75d29..5e46436f 100644
--- a/common/atomic.h
+++ b/common/atomic.h
@@ -91,12 +91,14 @@ inline uint DecrementRef(RefCount *ptr)
* changing the head without giving this a chance to actually swap in the new
* one (practically impossible with this little code, but...).
*/
-#define ATOMIC_REPLACE_HEAD(T, _head, _entry) do { \
- T _first = ATOMIC_LOAD(_head, almemory_order_acquire); \
- do { \
- ATOMIC_STORE(&(_entry)->next, _first, almemory_order_relaxed); \
- } while(ATOMIC_COMPARE_EXCHANGE_WEAK(_head, &_first, _entry, \
- almemory_order_acq_rel, almemory_order_acquire) == 0); \
-} while(0)
+template<typename T>
+inline void AtomicReplaceHead(std::atomic<T> &head, T newhead)
+{
+ T first_ = head.load(std::memory_order_acquire);
+ do {
+ newhead->next.store(first_, std::memory_order_relaxed);
+ } while(!head.compare_exchange_weak(first_, newhead,
+ std::memory_order_acq_rel, std::memory_order_acquire));
+}
#endif /* AL_ATOMIC_H */