Skip to content

Commit 43d8ca4

Browse files
committed
osd: replace deprecated atomic_store with std::atomic<shared_ptr>
Update shared pointer atomic operations to use C++20's `std::atomic<std::shared_ptr>` 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<const OSDMap>' is deprecated: use 'std::atomic<std::shared_ptr<T>>' 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<const OSDMap>' 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"))) | ^ 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 <[email protected]>
1 parent 2694580 commit 43d8ca4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/osd/OSD.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,13 +1669,24 @@ class OSD : public Dispatcher,
16691669
protected:
16701670

16711671
// -- osd map --
1672-
// TODO: switch to std::atomic<OSDMapRef> when C++20 will be available.
1673-
OSDMapRef _osdmap;
1672+
#ifdef __cpp_lib_atomic_shared_ptr
1673+
std::atomic<OSDMapRef> _osdmap;
1674+
#else
1675+
OSDMapRef _osdmap;
1676+
#endif
16741677
void set_osdmap(OSDMapRef osdmap) {
1678+
#ifdef __cpp_lib_atomic_shared_ptr
1679+
_osdmap.store(osdmap);
1680+
#else
16751681
std::atomic_store(&_osdmap, osdmap);
1682+
#endif
16761683
}
16771684
OSDMapRef get_osdmap() const {
1685+
#ifdef __cpp_lib_atomic_shared_ptr
1686+
return _osdmap.load();
1687+
#else
16781688
return std::atomic_load(&_osdmap);
1689+
#endif
16791690
}
16801691
epoch_t get_osdmap_epoch() const {
16811692
// XXX: performance?

0 commit comments

Comments
 (0)