aboutsummaryrefslogtreecommitdiffstats
path: root/common/atomic.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-08-01 13:28:53 -0700
committerChris Robinson <[email protected]>2019-08-01 13:43:32 -0700
commit65f7fc610e6a6101509906c0c9bbbd794c9a3737 (patch)
tree48e03a76d121d2927623c8982c149acb0a8d616e /common/atomic.h
parent380f3dc11de1b3d8e6a00b2920cb809cfb953c0d (diff)
Add a common base for auto-deleting ref-counted objects
Which will also work as the basis for a future intrusive_ptr
Diffstat (limited to 'common/atomic.h')
-rw-r--r--common/atomic.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/common/atomic.h b/common/atomic.h
index e34f35bb..5e9b04c6 100644
--- a/common/atomic.h
+++ b/common/atomic.h
@@ -6,14 +6,14 @@
using RefCount = std::atomic<unsigned int>;
-inline void InitRef(RefCount *ptr, unsigned int value)
-{ ptr->store(value, std::memory_order_relaxed); }
-inline unsigned int ReadRef(RefCount *ptr)
-{ return ptr->load(std::memory_order_acquire); }
-inline unsigned int IncrementRef(RefCount *ptr)
-{ return ptr->fetch_add(1u, std::memory_order_acq_rel)+1u; }
-inline unsigned int DecrementRef(RefCount *ptr)
-{ return ptr->fetch_sub(1u, std::memory_order_acq_rel)-1u; }
+inline void InitRef(RefCount &ref, unsigned int value)
+{ ref.store(value, std::memory_order_relaxed); }
+inline unsigned int ReadRef(RefCount &ref)
+{ return ref.load(std::memory_order_acquire); }
+inline unsigned int IncrementRef(RefCount &ref)
+{ return ref.fetch_add(1u, std::memory_order_acq_rel)+1u; }
+inline unsigned int DecrementRef(RefCount &ref)
+{ return ref.fetch_sub(1u, std::memory_order_acq_rel)-1u; }
/* WARNING: A livelock is theoretically possible if another thread keeps