From 6e114a7a70c90d575e5978c5bcac95307bec0140 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 19 Nov 2018 01:20:03 -0800 Subject: Replace ATOMIC_REPLACE_HEAD with an inline function --- common/atomic.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'common') 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 +inline void AtomicReplaceHead(std::atomic &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 */ -- cgit v1.2.3