1 #ifndef DataFormats_Common_AtomicPtrCache_h
2 #define DataFormats_Common_AtomicPtrCache_h
54 T const*
load()
const;
59 bool set(std::unique_ptr<T> iNewValue)
const;
85 auto ptr = iOther.m_data.load(std::memory_order_acquire);
87 m_data.store(
new T{*ptr}, std::memory_order_release);
92 auto ptr = iOther.
m_data.load(std::memory_order_acquire);
94 auto ourPtr = m_data.load(std::memory_order_acquire);
95 if (ourPtr !=
nullptr) {
98 m_data.store(
new T{*ptr}, std::memory_order_release);
101 delete m_data.exchange(
nullptr, std::memory_order_acq_rel);
106 template <
typename T>
108 delete m_data.load(std::memory_order_acquire);
111 template <
typename T>
113 return m_data.load(std::memory_order_acquire);
116 template <
typename T>
118 return m_data.load(std::memory_order_acquire);
121 template <
typename T>
123 return nullptr != m_data.load(std::memory_order_acquire);
126 template <
typename T>
129 T* expected =
nullptr;
130 if ((retValue = m_data.compare_exchange_strong(expected, iNewValue.get(), std::memory_order_acq_rel))) {
136 template <
typename T>
138 delete m_data.exchange(
nullptr, std::memory_order_acq_rel);
141 template <
typename T>
143 T*
tmp = m_data.exchange(
nullptr);
T const & operator*() const
void reset()
unsets the value and deletes the memory
AtomicPtrCache & operator=(const AtomicPtrCache< T > &)
bool set(std::unique_ptr< T > iNewValue) const
T const * operator->() const
std::atomic< T * > m_data