8#ifndef MADNESS_WORLD_ATOMIC_SHARED_PTR_H__INCLUDED
9#define MADNESS_WORLD_ATOMIC_SHARED_PTR_H__INCLUDED
38#if defined(__cpp_lib_atomic_shared_ptr)
39 std::atomic<std::shared_ptr<T>>
ptr_;
41 std::shared_ptr<T>
do_load()
const noexcept {
42 return ptr_.load(std::memory_order_relaxed);
44 void do_store(std::shared_ptr<T>
p)
noexcept {
45 ptr_.store(std::move(
p), std::memory_order_relaxed);
55#if __cplusplus >= 202002L
62 std::shared_ptr<T>
do_load() const noexcept {
63 return std::atomic_load_explicit(&
ptr_, std::memory_order_relaxed);
66 std::atomic_store_explicit(&
ptr_, std::move(
p), std::memory_order_relaxed);
68#if __cplusplus >= 202002L
86 :
ptr_(other.exchange({}, std::memory_order_relaxed)) {}
90 if (
this != &other)
do_store(other.do_load());
97 if (
this != &other)
do_store(other.exchange({}, std::memory_order_relaxed));
113 explicit operator bool() const noexcept {
return bool(
do_load()); }
129 operator std::shared_ptr<T>() const noexcept {
return do_load(); }
141 std::memory_order order = std::memory_order_seq_cst)
noexcept {
142#if defined(__cpp_lib_atomic_shared_ptr)
143 return ptr_.exchange(std::move(
p), order);
145#if __cplusplus >= 202002L
151 return std::atomic_exchange_explicit(&
ptr_, std::move(
p), order);
152#if __cplusplus >= 202002L
Definition atomic_shared_ptr.h:37
atomic_shared_ptr(atomic_shared_ptr &&other) noexcept
Definition atomic_shared_ptr.h:85
void do_store(std::shared_ptr< T > p) noexcept
Definition atomic_shared_ptr.h:65
constexpr atomic_shared_ptr() noexcept=default
T * operator->() noexcept
Definition atomic_shared_ptr.h:119
std::shared_ptr< T > ptr_
Definition atomic_shared_ptr.h:48
void reset()
Replaces the stored pointer with an empty shared pointer.
Definition atomic_shared_ptr.h:111
void reset(T *p)
Replaces the stored pointer, adopting p (may be null).
Definition atomic_shared_ptr.h:108
long use_count() const noexcept
Definition atomic_shared_ptr.h:131
const T * operator->() const noexcept
Definition atomic_shared_ptr.h:125
bool operator==(const atomic_shared_ptr &r) const noexcept
Definition atomic_shared_ptr.h:133
atomic_shared_ptr & operator=(std::shared_ptr< T > p) noexcept
Assigns a new shared_ptr value atomically.
Definition atomic_shared_ptr.h:102
atomic_shared_ptr(const atomic_shared_ptr &other) noexcept
Copy-constructs by atomically loading the other pointer.
Definition atomic_shared_ptr.h:80
atomic_shared_ptr & operator=(const atomic_shared_ptr &other) noexcept
Copy-assigns by atomically loading from other and storing.
Definition atomic_shared_ptr.h:89
bool operator!=(const atomic_shared_ptr &r) const noexcept
Definition atomic_shared_ptr.h:134
std::shared_ptr< T > exchange(std::shared_ptr< T > p={}, std::memory_order order=std::memory_order_seq_cst) noexcept
Definition atomic_shared_ptr.h:140
std::shared_ptr< T > do_load() const noexcept
Definition atomic_shared_ptr.h:62
atomic_shared_ptr & operator=(atomic_shared_ptr &&other) noexcept
Definition atomic_shared_ptr.h:96
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:28
Macros and tools pertaining to the configuration of MADNESS.
#define MADNESS_PRAGMA_CLANG(x)
Definition madness_config.h:200
#define MADNESS_PRAGMA_GCC(x)
Definition madness_config.h:205
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
static double pop(std::vector< double > &v)
Definition SCF.cc:115