From: Kefu Chai Date: Tue, 25 Mar 2025 13:40:00 +0000 (+0800) Subject: common/ceph_context: Fix std::atomic compatibility X-Git-Tag: v20.3.0~251^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d51ed04ef611af4ffa4c2cedae707874410b623c;p=ceph.git common/ceph_context: Fix std::atomic compatibility Previously, we relied on the __GNUC__ macro to check for std::atomic support, which was inaccurate. This approach failed with Clang builds using libstdc++, even when the feature was implemented. The warning looks like: ``` /usr/lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/bits/shared_ptr_atomic.h:131:5: note: 'atomic_load_explicit>' has been explicitly marked deprecated here 131 | _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") | ^ ``` This change uses a standard-compliant feature test macro (__cpp_lib_atomic_shared_ptr) to correctly detect support for std::atomic. This resolves compilation issues and improves portability across different compilers and standard library implementations. Refs 5b0d849730ce20d68ffafcb612c5f6fc8b87dd9a Signed-off-by: Kefu Chai --- diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index 103f39fb2913e..5a2619a8f2be6 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -283,19 +283,17 @@ 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 +#ifdef __cpp_lib_atomic_shared_ptr _mon_addrs.store(std::move(ptr), std::memory_order_relaxed); +#else + atomic_store_explicit(&_mon_addrs, 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 +#ifdef __cpp_lib_atomic_shared_ptr auto ptr = _mon_addrs.load(std::memory_order_relaxed); +#else + auto ptr = atomic_load_explicit(&_mon_addrs, std::memory_order_relaxed); #endif return ptr; } @@ -317,11 +315,10 @@ private: int _crypto_inited; -#if defined(__GNUC__) && __GNUC__ < 12 - // workaround for GCC 11 bug - std::shared_ptr> _mon_addrs; -#else +#ifdef __cpp_lib_atomic_shared_ptr std::atomic>> _mon_addrs; +#else + std::shared_ptr> _mon_addrs; #endif /* libcommon service thread.