Skip to content

Commit 6304ba5

Browse files
committed
librbd: replace deprecated atomic_store with std::atomic<shared_ptr>
Update shared pointer atomic operations to use C++20's std::atomic<std::shared_ptr<T>> 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<neorados::IOContext>' is deprecated: use 'std::atomic<std::shared_ptr<T>>' 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<neorados::IOContext>' has been explicitly marked deprecated here 181 | _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") | ^ /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 <[email protected]>
1 parent 2694580 commit 6304ba5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/librbd/ImageCtx.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,11 +1007,19 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) {
10071007
}
10081008

10091009
// atomically reset the data IOContext to new version
1010+
#ifdef __cpp_lib_atomic_shared_ptr
1011+
data_io_context.store(ctx);
1012+
#else
10101013
atomic_store(&data_io_context, ctx);
1014+
#endif
10111015
}
10121016

10131017
IOContext ImageCtx::get_data_io_context() const {
1018+
#ifdef __cpp_lib_atomic_shared_ptr
1019+
return data_io_context.load();
1020+
#else
10141021
return atomic_load(&data_io_context);
1022+
#endif
10151023
}
10161024

10171025
IOContext ImageCtx::duplicate_data_io_context() const {

src/librbd/ImageCtx.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,11 @@ namespace librbd {
366366
ceph::mutex **timer_lock);
367367

368368
private:
369+
#ifdef __cpp_lib_atomic_shared_ptr
370+
std::atomic<std::shared_ptr<neorados::IOContext>> data_io_context;
371+
#else
369372
std::shared_ptr<neorados::IOContext> data_io_context;
373+
#endif
370374
};
371375
}
372376

0 commit comments

Comments
 (0)