From 43d8ca484de84029323321f05662c27af35be356 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 29 Mar 2025 21:29:43 +0800 Subject: [PATCH] osd: replace deprecated atomic_store with std::atomic Update shared pointer atomic operations to use C++20's `std::atomic` instead of the deprecated `atomic_store` functions. This change addresses deprecation warnings from GCC-15's libstdc++ where atomic shared pointer operations outside the `std::atomic` class are being phased out: ``` In file included from /home/kefu/dev/ceph/src/osd/Watch.cc:9: /home/kefu/dev/ceph/src/osd/OSD.h:1675:10: warning: 'atomic_store' is deprecated: use 'std::atomic>' instead [-Wdeprecated-declarations] 1675 | std::atomic_store(&_osdmap, osdmap); | ^ /usr/lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/bits/shared_ptr_atomic.h:181:5: note: 'atomic_store' has been explicitly marked deprecated here 181 | _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") | ^ /usr/lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/x86_64-redhat-linux/bits/c++config.h:2055:45: note: expanded from macro '_GLIBCXX20_DEPRECATED_SUGGEST' 2055 | # define _GLIBCXX20_DEPRECATED_SUGGEST(ALT) _GLIBCXX_DEPRECATED_SUGGEST(ALT) | ^ /usr/lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/x86_64-redhat-linux/bits/c++config.h:2023:19: note: expanded from macro '_GLIBCXX_DEPRECATED_SUGGEST' 2023 | __attribute__ ((__deprecated__ ("use '" ALT "' instead"))) | ^ In file included from /home/kefu/dev/ceph/src/osd/Watch.cc:9: ``` The implementation now uses the standard-compliant approach that's recommended in the compiler warnings, while maintaining backward compatibility with older compilers by conditionally selecting the appropriate implementation. Signed-off-by: Kefu Chai --- src/osd/OSD.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/osd/OSD.h b/src/osd/OSD.h index d2d16c5b7d2..1d41a44f917 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1669,13 +1669,24 @@ protected: protected: // -- osd map -- - // TODO: switch to std::atomic when C++20 will be available. - OSDMapRef _osdmap; +#ifdef __cpp_lib_atomic_shared_ptr + std::atomic _osdmap; +#else + OSDMapRef _osdmap; +#endif void set_osdmap(OSDMapRef osdmap) { +#ifdef __cpp_lib_atomic_shared_ptr + _osdmap.store(osdmap); +#else std::atomic_store(&_osdmap, osdmap); +#endif } OSDMapRef get_osdmap() const { +#ifdef __cpp_lib_atomic_shared_ptr + return _osdmap.load(); +#else return std::atomic_load(&_osdmap); +#endif } epoch_t get_osdmap_epoch() const { // XXX: performance? -- 2.39.5