diff options
Diffstat (limited to 'core/templates/safe_refcount.h')
-rw-r--r-- | core/templates/safe_refcount.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h index 6aebc24ec3..cdc9908a5f 100644 --- a/core/templates/safe_refcount.h +++ b/core/templates/safe_refcount.h @@ -47,10 +47,18 @@ // value and, as an important benefit, you can be sure the value is properly synchronized // even with threads that are already running. +// This is used in very specific areas of the engine where it's critical that these guarantees are held +#define SAFE_NUMERIC_TYPE_PUN_GUARANTEES(m_type) \ + static_assert(sizeof(SafeNumeric<m_type>) == sizeof(m_type)); \ + static_assert(alignof(SafeNumeric<m_type>) == alignof(m_type)); \ + static_assert(std::is_trivially_destructible<std::atomic<m_type>>::value); + template <class T> class SafeNumeric { std::atomic<T> value; + static_assert(std::atomic<T>::is_always_lock_free); + public: _ALWAYS_INLINE_ void set(T p_value) { value.store(p_value, std::memory_order_release); @@ -128,6 +136,8 @@ public: class SafeFlag { std::atomic_bool flag; + static_assert(std::atomic_bool::is_always_lock_free); + public: _ALWAYS_INLINE_ bool is_set() const { return flag.load(std::memory_order_acquire); |