From 5b0d849730ce20d68ffafcb612c5f6fc8b87dd9a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 9 Oct 2024 23:21:11 +0200 Subject: [PATCH] common/ceph_context: use std::atomic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes the compiler warning: src/common/ceph_context.h: In member function ‘std::shared_ptr > ceph::common::CephContext::get_mon_addrs() const’: src/common/ceph_context.h:288:36: warning: ‘std::shared_ptr<_Tp> std::atomic_load_explicit(const shared_ptr<_Tp>*, memory_order) [with _Tp = vector]’ is deprecated: use 'std::atomic>' instead [-Wdeprecated-declarations] 288 | auto ptr = atomic_load_explicit(&_mon_addrs, std::memory_order_relaxed); | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/shared_ptr_atomic.h:133:5: note: declared here 133 | atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) | ^~~~~~~~~~~~~~~~~~~~ The modernized version does not build with GCC 11, so this patch contains both versions for now, switched by a `__GNUC__` preprocessor check. Signed-off-by: Max Kellermann --- src/common/ceph_context.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index f1877647877ab..6a02d5c5bf1fc 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -282,10 +282,20 @@ public: void set_mon_addrs(const MonMap& mm); void set_mon_addrs(const std::vector& in) { auto ptr = std::make_shared>(in); +#if defined(__GNUC__) && __GNUC__ < 12 + // workaround for GCC 11 bug atomic_store_explicit(&_mon_addrs, std::move(ptr), std::memory_order_relaxed); +#else + _mon_addrs.store(std::move(ptr), std::memory_order_relaxed); +#endif } std::shared_ptr> get_mon_addrs() const { +#if defined(__GNUC__) && __GNUC__ < 12 + // workaround for GCC 11 bug auto ptr = atomic_load_explicit(&_mon_addrs, std::memory_order_relaxed); +#else + auto ptr = _mon_addrs.load(std::memory_order_relaxed); +#endif return ptr; } @@ -306,7 +316,12 @@ private: int _crypto_inited; +#if defined(__GNUC__) && __GNUC__ < 12 + // workaround for GCC 11 bug std::shared_ptr> _mon_addrs; +#else + std::atomic>> _mon_addrs; +#endif /* libcommon service thread. * SIGHUP wakes this thread, which then reopens logfiles */ -- 2.39.5