[base] Fix warning about deprecated usage of atomic_store

Fixes the following gcc warnings:
````
base/atomic_shared_ptr.hpp:19:52: warning: ‘void std::atomic_store(shared_ptr<_Tp>*, shared_ptr<_Tp>)
[with _Tp = const editor::EditorConfig]’
is deprecated: use 'std::atomic<std::shared_ptr<T>>' instead [-Wdeprecated-declarations]
   19 |   void Set(ValueType value) noexcept { atomic_store(&m_wrapped, value); }
      |                                        ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
````

Signed-off-by: Ferenc Géczi <ferenc.gm@gmail.com>
This commit is contained in:
Ferenc Géczi 2024-12-21 00:00:00 +00:00
parent 0873f97754
commit ed317aa18e
No known key found for this signature in database
GPG key ID: D8C1C26616451E4B

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);
};