9#if defined(COOPSYNC_TBB_DOXYGEN) || \
10 (defined(COOPSYNC_TBB_HAS_ATOMIC_REF_CONDITION) && \
11 COOPSYNC_TBB_HAS_ATOMIC_REF_CONDITION == 1)
17#include "coopsync_tbb/detail/macros.hpp"
18#include "coopsync_tbb/detail/wait_queue.hpp"
31 static_assert(std::is_trivially_copyable<T>::value,
32 "atomic_ref_condition requires trivially copyable type");
34 std::atomic_ref<T>::is_always_lock_free || !std::is_volatile<T>::value,
35 "If std::atomic<T> is not always lock-free, T must not be volatile");
40 using value_type =
typename std::atomic_ref<T>::value_type;
88 std::memory_order order = std::memory_order_seq_cst);
100 std::atomic_ref<T>&
atomic() noexcept;
105 const std::atomic_ref<T>&
atomic() const noexcept;
110 std::atomic_ref<T>& operator*() noexcept;
115 const std::atomic_ref<T>& operator*() const noexcept;
120 std::atomic_ref<T>* operator->() noexcept;
125 const std::atomic_ref<T>* operator->() const noexcept;
128 std::atomic_ref<T> m_value;
129 detail::wait_queue m_waiters;
137 : m_value(other.m_value) {}
141 assert(m_waiters.empty());
146 assert(order != std::memory_order_release);
147 assert(order != std::memory_order_acq_rel);
152 const auto current = m_value.load(order);
153 if (std::memcmp(¤t, &old,
sizeof(
value_type)) != 0) {
156 m_waiters.wait_if([
this, &old, order] {
157 const auto current = m_value.load(order);
158 return std::memcmp(¤t, &old,
sizeof(
value_type)) == 0;
165 m_waiters.resume_one();
170 m_waiters.resume_all();
206 "atomic_ref_condition is not supported on this platform. Please check the COOPSYNC_TBB_HAS_ATOMIC_REF_CONDITION macro."
std::atomic_ref< T > & operator*() noexcept
Access to the internal atomic_ref value.
Definition atomic_ref_condition.hpp:184
std::atomic_ref< T > * operator->() noexcept
Access to the internal atomic_ref value.
Definition atomic_ref_condition.hpp:194
void notify_all()
Resumes all tasks suspended waiting on this atomic_ref_condition.
Definition atomic_ref_condition.hpp:169
typename std::atomic_ref< T >::value_type value_type
The value type of the atomic_ref_condition, same as the value type of the internal atomic_ref.
Definition atomic_ref_condition.hpp:40
void wait(value_type old, std::memory_order order=std::memory_order_seq_cst)
Suspends the calling task until the internal atomic_ref value is not equal to specified value....
Definition atomic_ref_condition.hpp:145
~atomic_ref_condition()
Destroys the atomic_ref_condition.
Definition atomic_ref_condition.hpp:140
atomic_ref_condition & operator=(atomic_ref_condition &&)=delete
The atomic_ref_condition is not move-assignable.
atomic_ref_condition(atomic_ref_condition &&)=delete
The atomic_ref_condition is not move-constructible.
atomic_ref_condition(T &value)
Constructs a new atomic_ref_condition that refers to the given value.
Definition atomic_ref_condition.hpp:133
std::atomic_ref< T > & atomic() noexcept
Access to the internal atomic_ref value.
Definition atomic_ref_condition.hpp:174
atomic_ref_condition & operator=(const atomic_ref_condition &)=delete
The atomic_ref_condition is not copy-assignable.
void notify_one()
Resumes one task suspended waiting on this atomic_ref_condition, if there is any.
Definition atomic_ref_condition.hpp:164
Feature test macros for the CoopSync_TBB public API.
Main namespace of the library, containing all public APIs.
Definition wait_for.hpp:11