[base] Fix warning about deprecated usage of atomic_store #9910

Open
Ferenc- wants to merge 1 commit from fix-deprecated-atomic-load into master

View file

@ -16,11 +16,26 @@ public:
AtomicSharedPtr() = default;
void Set(ValueType value) noexcept { atomic_store(&m_wrapped, value); }
ValueType Get() const noexcept { return atomic_load(&m_wrapped); }
// TODO drop this condition and the else branch when Apple and Google will finally
// also support the full C++20 standard
// including the partial template specialization of `std::atomic` for `std::shared_ptr<T>`
// mandated by `P0718R2`:
// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0718r2.html#3.2
// The support status can be also tracked at:
// https://en.cppreference.com/w/cpp/compiler_support/20#cpp_lib_atomic_shared_ptr_201711L
#if defined(_SHARED_PTR_ATOMIC_H)
void Set(ValueType value) noexcept { m_wrapped.store(value); }
ValueType Get() const noexcept { return m_wrapped.load(); }
private:
std::atomic<ValueType> m_wrapped = std::make_shared<ContentType>();
#else
void Set(ValueType value) noexcept { atomic_store(&m_wrapped, value); }
ValueType Get() const noexcept { return atomic_load(&m_wrapped); }
private:
ValueType m_wrapped = std::make_shared<ContentType>();
#endif
DISALLOW_COPY_AND_MOVE(AtomicSharedPtr);
};