|
MADNESS 0.10.1
|
#include <atomic_shared_ptr.h>
Public Member Functions | |
| constexpr | atomic_shared_ptr () noexcept=default |
| atomic_shared_ptr (atomic_shared_ptr &&other) noexcept | |
| atomic_shared_ptr (const atomic_shared_ptr &other) noexcept | |
| Copy-constructs by atomically loading the other pointer. | |
| atomic_shared_ptr (std::shared_ptr< T > p) noexcept | |
| std::shared_ptr< T > | exchange (std::shared_ptr< T > p={}, std::memory_order order=std::memory_order_seq_cst) noexcept |
| operator bool () const noexcept | |
| operator std::shared_ptr< T > () const noexcept | |
| bool | operator!= (const atomic_shared_ptr &r) const noexcept |
| const T * | operator-> () const noexcept |
| T * | operator-> () noexcept |
| atomic_shared_ptr & | operator= (atomic_shared_ptr &&other) noexcept |
| atomic_shared_ptr & | operator= (const atomic_shared_ptr &other) noexcept |
Copy-assigns by atomically loading from other and storing. | |
| atomic_shared_ptr & | operator= (std::shared_ptr< T > p) noexcept |
| Assigns a new shared_ptr value atomically. | |
| bool | operator== (const atomic_shared_ptr &r) const noexcept |
| void | reset () |
| Replaces the stored pointer with an empty shared pointer. | |
| void | reset (T *p) |
Replaces the stored pointer, adopting p (may be null). | |
| long | use_count () const noexcept |
Private Member Functions | |
| std::shared_ptr< T > | do_load () const noexcept |
| void | do_store (std::shared_ptr< T > p) noexcept |
Private Attributes | |
| std::shared_ptr< T > | ptr_ |
A std::shared_ptr-like handle backed by atomic storage.
Uses std::atomic<std::shared_ptr<T>> when available (C++20), otherwise falls back to the pre-C++20 atomic free functions on std::shared_ptr. The public API mirrors std::shared_ptr (copy construction/assignment, operator->, operator bool, implicit conversion, reset, use_count, equality comparison) plus a single extension, exchange(), needed for the move-optimisation in Future::get()&&.
exchange. This is necessary because (a) user-declared copy operations would otherwise suppress the implicit move operations, and (b) std::atomic is non-movable in the C++20 backend, so the implicit move would silently fall back to copy.memory_order_relaxed, relying on the caller to provide necessary ordering guarantees. The exception is exchange(), which defaults to memory_order_seq_cst to match the pre-C++20 std::atomic_exchange behaviour it replaces.
|
constexprdefaultnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Copy-constructs by atomically loading the other pointer.
|
inlinenoexcept |
Move-constructs by atomically taking the value from other, which is left empty. Uses memory_order_relaxed (consistent with do_load / do_store); caller is responsible for any synchronization.
|
inlineprivatenoexcept |
References madness::atomic_shared_ptr< T >::ptr_.
Referenced by madness::atomic_shared_ptr< T >::operator bool(), madness::atomic_shared_ptr< madness::FutureImpl< bool > >::operator std::shared_ptr< madness::FutureImpl< bool > >(), madness::atomic_shared_ptr< T >::operator!=(), madness::atomic_shared_ptr< T >::operator->(), madness::atomic_shared_ptr< T >::operator->(), madness::atomic_shared_ptr< T >::operator==(), and madness::atomic_shared_ptr< T >::use_count().
|
inlineprivatenoexcept |
|
inlinenoexcept |
Atomically replaces the stored pointer with p and returns the old value. This is the only operation that differs from std::shared_ptr. Defaults to memory_order_seq_cst to match the pre-C++20 std::atomic_exchange behaviour this replaces.
|
inlineexplicitnoexcept |
References madness::atomic_shared_ptr< T >::do_load().
|
inlinenoexcept |
Implicit conversion to shared_ptr, used for lifetime extension and APIs that require a shared_ptr (e.g. RemoteReference).
|
inlinenoexcept |
References madness::atomic_shared_ptr< T >::do_load().
|
inlinenoexcept |
Dereferences the stored pointer, const overload. Safe because do_load() returns a shared_ptr temporary whose lifetime extends to the end of the full expression containing the -> call, keeping the referent alive across the dereference.
References madness::atomic_shared_ptr< T >::do_load().
|
inlinenoexcept |
Dereferences the stored pointer. Safe because do_load() returns a shared_ptr temporary whose lifetime extends to the end of the full expression containing the -> call, keeping the referent alive across the dereference.
References madness::atomic_shared_ptr< T >::do_load().
|
inlinenoexcept |
Move-assigns by atomically taking the value from other, which is left empty. Self-assignment is a no-op.
References madness::atomic_shared_ptr< T >::do_store().
|
inlinenoexcept |
Copy-assigns by atomically loading from other and storing.
References madness::atomic_shared_ptr< T >::do_store().
|
inlinenoexcept |
Assigns a new shared_ptr value atomically.
References madness::atomic_shared_ptr< T >::do_store(), and p().
|
inlinenoexcept |
References madness::atomic_shared_ptr< T >::do_load().
|
inline |
Replaces the stored pointer with an empty shared pointer.
References madness::atomic_shared_ptr< T >::do_store().
|
inline |
Replaces the stored pointer, adopting p (may be null).
References madness::atomic_shared_ptr< T >::do_store(), and p().
|
inlinenoexcept |
References madness::atomic_shared_ptr< T >::do_load().
|
private |