Common: Less strict memory ordering requirements for IObj

Applies the same relaxed restrictions as applied to boo in
4d91a1b3c3
and
84f62a0f2c
This commit is contained in:
Lioncash 2019-08-25 00:06:59 -04:00
parent c46bb3f72b
commit a8f4c1d34a
1 changed files with 5 additions and 3 deletions

View File

@ -150,10 +150,12 @@ protected:
virtual ~IObj() = default; virtual ~IObj() = default;
public: public:
void increment() noexcept { m_refCount++; } void increment() noexcept { m_refCount.fetch_add(std::memory_order_relaxed); }
void decrement() noexcept { void decrement() noexcept {
if (m_refCount.fetch_sub(1) == 1) if (m_refCount.fetch_sub(1, std::memory_order_release) == 1) {
std::atomic_thread_fence(std::memory_order_acquire);
delete this; delete this;
}
} }
}; };
@ -373,7 +375,7 @@ constexpr T clamp(T a, T val, T b) {
} }
template <typename T> template <typename T>
constexpr T ClampFull(float in) { constexpr T ClampFull(float in) noexcept {
if (std::is_floating_point<T>()) { if (std::is_floating_point<T>()) {
return in; return in;
} else { } else {