diff options
author | Chris Robinson <[email protected]> | 2023-12-03 23:36:07 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-12-03 23:36:07 -0800 |
commit | b6a68e8d510610e181d638ff993e327059bd6018 (patch) | |
tree | 3c58b34d96036c3f6036bc96bc8a2f80015b1310 /common | |
parent | 859319fa7864ed6a81af1f12c68627ab58bb7a7d (diff) |
Remove some unnecessary atomic wrappers
Diffstat (limited to 'common')
-rw-r--r-- | common/atomic.h | 13 | ||||
-rw-r--r-- | common/intrusive_ptr.h | 2 |
2 files changed, 6 insertions, 9 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; } diff --git a/common/intrusive_ptr.h b/common/intrusive_ptr.h index 27075347..714a5617 100644 --- a/common/intrusive_ptr.h +++ b/common/intrusive_ptr.h @@ -11,7 +11,7 @@ namespace al { template<typename T> class intrusive_ref { - RefCount mRef{1u}; + std::atomic<unsigned int> mRef{1u}; public: unsigned int add_ref() noexcept { return IncrementRef(mRef); } |