diff options
Diffstat (limited to 'common/atomic.h')
-rw-r--r-- | common/atomic.h | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/common/atomic.h b/common/atomic.h index 5e9b04c6..a579dcab 100644 --- a/common/atomic.h +++ b/common/atomic.h @@ -4,15 +4,12 @@ #include <atomic> -using RefCount = std::atomic<unsigned int>; - -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) +template<typename T> +auto IncrementRef(std::atomic<T> &ref) noexcept { return ref.fetch_add(1u, std::memory_order_acq_rel)+1u; } -inline unsigned int DecrementRef(RefCount &ref) + +template<typename T> +auto DecrementRef(std::atomic<T> &ref) noexcept { return ref.fetch_sub(1u, std::memory_order_acq_rel)-1u; } |