CoopSync for TBB 0.1.0
Cooperative synchronization primitives for TBB resumable tasks
Loading...
Searching...
No Matches
coopsync_tbb::atomic_ref_condition< T > Class Template Reference

Wrapper around std::atomic_ref that provides atomic waiting which suspends the calling task instead of blocking it. More...

#include <coopsync_tbb/atomic_ref_condition.hpp>

Public Types

using value_type = typename std::atomic_ref<T>::value_type
 The value type of the atomic_ref_condition, same as the value type of the internal atomic_ref.

Public Member Functions

 atomic_ref_condition (T &value)
 Constructs a new atomic_ref_condition that refers to the given value.
 atomic_ref_condition (const atomic_ref_condition &other)
 The atomic_ref_condition is copy-constructible. The copy constructor creates a new atomic_ref_condition that refers to the same internal atomic object as the original but does not share the waiting queue.
atomic_ref_condition & operator= (const atomic_ref_condition &)=delete
 The atomic_ref_condition is not copy-assignable.
 atomic_ref_condition (atomic_ref_condition &&)=delete
 The atomic_ref_condition is not move-constructible.
atomic_ref_condition & operator= (atomic_ref_condition &&)=delete
 The atomic_ref_condition is not move-assignable.
 ~atomic_ref_condition ()
 Destroys the atomic_ref_condition.
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. If the internal atomic_ref value is not equal to old, the function returns immediately. Otherwise, the task is suspended. The task will be resumed once associated notify function is called and the internal atomic_ref value is not equal to old.
void notify_one ()
 Resumes one task suspended waiting on this atomic_ref_condition, if there is any.
void notify_all ()
 Resumes all tasks suspended waiting on this atomic_ref_condition.
std::atomic_ref< T > & atomic () noexcept
 Access to the internal atomic_ref value.
const std::atomic_ref< T > & atomic () const noexcept
 Access to the internal atomic_ref value.
std::atomic_ref< T > & operator* () noexcept
 Access to the internal atomic_ref value.
const std::atomic_ref< T > & operator* () const noexcept
 Access to the internal atomic_ref value.
std::atomic_ref< T > * operator-> () noexcept
 Access to the internal atomic_ref value.
const std::atomic_ref< T > * operator-> () const noexcept
 Access to the internal atomic_ref value.

Detailed Description

template<typename T>
class coopsync_tbb::atomic_ref_condition< T >

Wrapper around std::atomic_ref that provides atomic waiting which suspends the calling task instead of blocking it.

Template Parameters
TThe type of the value contained in the atomic_ref_condition.

Available only if the standard library supports std::atomic_ref (C++20). Compliance can be checked with COOPSYNC_TBB_HAS_ATOMIC_REF_CONDITION.

Constructor & Destructor Documentation

◆ atomic_ref_condition() [1/2]

template<typename T>
coopsync_tbb::atomic_ref_condition< T >::atomic_ref_condition ( T & value)
explicit

Constructs a new atomic_ref_condition that refers to the given value.

Parameters
valueA reference to a value to construct the internal atomic_ref from. The value must remain valid for the lifetime of the atomic_ref_condition.

◆ atomic_ref_condition() [2/2]

template<typename T>
coopsync_tbb::atomic_ref_condition< T >::atomic_ref_condition ( const atomic_ref_condition< T > & other)

The atomic_ref_condition is copy-constructible. The copy constructor creates a new atomic_ref_condition that refers to the same internal atomic object as the original but does not share the waiting queue.

Parameters
otherThe atomic_ref_condition to share internal state with.

◆ ~atomic_ref_condition()

Destroys the atomic_ref_condition.

Note
The destructor must not be called while there are still tasks waiting on the atomic_ref_condition. The destructor does not notify or resume any waiting tasks.

Member Function Documentation

◆ atomic() [1/2]

template<typename T>
const std::atomic_ref< T > & coopsync_tbb::atomic_ref_condition< T >::atomic ( ) const
noexcept

Access to the internal atomic_ref value.

Returns
Const reference to the internal atomic_ref value. Remains valid for the lifetime of the atomic_ref_condition.

◆ atomic() [2/2]

template<typename T>
std::atomic_ref< T > & coopsync_tbb::atomic_ref_condition< T >::atomic ( )
noexcept

Access to the internal atomic_ref value.

Returns
Reference to the internal atomic_ref value. Remains valid for the lifetime of the atomic_ref_condition.

◆ operator*() [1/2]

template<typename T>
const std::atomic_ref< T > & coopsync_tbb::atomic_ref_condition< T >::operator* ( ) const
noexcept

Access to the internal atomic_ref value.

Returns
Const reference to the internal atomic_ref value. Remains valid for the lifetime of the atomic_ref_condition.

◆ operator*() [2/2]

template<typename T>
std::atomic_ref< T > & coopsync_tbb::atomic_ref_condition< T >::operator* ( )
noexcept

Access to the internal atomic_ref value.

Returns
Reference to the internal atomic_ref value. Remains valid for the lifetime of the atomic_ref_condition.

◆ operator->() [1/2]

template<typename T>
const std::atomic_ref< T > * coopsync_tbb::atomic_ref_condition< T >::operator-> ( ) const
noexcept

Access to the internal atomic_ref value.

Returns
Const pointer to the internal atomic_ref value. Remains valid for the lifetime of the atomic_ref_condition.

◆ operator->() [2/2]

template<typename T>
std::atomic_ref< T > * coopsync_tbb::atomic_ref_condition< T >::operator-> ( )
noexcept

Access to the internal atomic_ref value.

Returns
Pointer to the internal atomic_ref value. Remains valid for the lifetime of the atomic_ref_condition.

◆ wait()

template<typename T>
void coopsync_tbb::atomic_ref_condition< T >::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. If the internal atomic_ref value is not equal to old, the function returns immediately. Otherwise, the task is suspended. The task will be resumed once associated notify function is called and the internal atomic_ref value is not equal to old.

Parameters
oldThe value to compare the internal atomic_ref value to. The task will be suspended while the internal atomic_ref value is equal to old.
orderThe memory order to use for loading the internal atomic_ref value. Must not be std::memory_order_release or std::memory_order_acq_rel.
Note
Due to ABA problem, transitions from old to a different value and back to old may be missed.
The comparison is done by bitwise comparison of the internal atomic_ref value and old, not by operator==. The comparison may be affected by padding bytes.

The documentation for this class was generated from the following file: