From 6304ba5f7fd5d32afe33e7234e5a90ad48afc862 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 29 Mar 2025 21:10:05 +0800 Subject: [PATCH] librbd: 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: ``` /home/kefu/dev/ceph/src/librbd/ImageCtx.cc:1010:5: warning: 'atomic_store' is deprecated: use 'std::atomic>' instead [-Wdeprecated-declarations] 1010 | atomic_store(&data_io_context, ctx); | ^ /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"))) | ^ ``` 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/librbd/ImageCtx.cc | 8 ++++++++ src/librbd/ImageCtx.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 0842ba3d56a..f7d6120b1d1 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -1007,11 +1007,19 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) { } // atomically reset the data IOContext to new version +#ifdef __cpp_lib_atomic_shared_ptr + data_io_context.store(ctx); +#else atomic_store(&data_io_context, ctx); +#endif } IOContext ImageCtx::get_data_io_context() const { +#ifdef __cpp_lib_atomic_shared_ptr + return data_io_context.load(); +#else return atomic_load(&data_io_context); +#endif } IOContext ImageCtx::duplicate_data_io_context() const { diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index 84c9284e31c..c10ec8bdfaa 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -366,7 +366,11 @@ namespace librbd { ceph::mutex **timer_lock); private: +#ifdef __cpp_lib_atomic_shared_ptr + std::atomic> data_io_context; +#else std::shared_ptr data_io_context; +#endif }; } -- 2.39.5