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

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

#include <coopsync_tbb/atomic_condition.hpp>

Public Types

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

Public Member Functions

 atomic_condition ()=default
 Constructs a new atomic_condition. No initialization of the atomic value takes place.
 atomic_condition (T value)
 Constructs a new atomic_condition with the given initial value. This operation is not atomic.
 atomic_condition (const atomic_condition &)=delete
 The atomic_condition is not copy-constructible.
atomic_condition & operator= (const atomic_condition &)=delete
 The atomic_condition is not copy-assignable.
 atomic_condition (atomic_condition &&)=delete
 The atomic_condition is not move-constructible.
atomic_condition & operator= (atomic_condition &&)=delete
 The atomic_condition is not move-assignable.
 ~atomic_condition ()
 Destroys the atomic_condition.
void wait (value_type old, std::memory_order order=std::memory_order_seq_cst)
 Suspends the calling task until the internal atomic value is not equal to specified value. If the internal atomic value is not equal to old, the function returns immediately. Otherwise, the task is suspended. The task will be resumed once notify_one or notify_all is called and the internal atomic value is not equal to old.
void notify_one ()
 Resumes one task suspended waiting on this atomic_condition, if there is any.
void notify_all ()
 Resumes all tasks suspended waiting on this atomic_condition.
std::atomic< T > & atomic () noexcept
 Access to the internal atomic value.
const std::atomic< T > & atomic () const noexcept
 Access to the internal atomic value.
std::atomic< T > & operator* () noexcept
 Access to the internal atomic value.
const std::atomic< T > & operator* () const noexcept
 Access to the internal atomic value.
std::atomic< T > * operator-> () noexcept
 Access to the internal atomic value.
const std::atomic< T > * operator-> () const noexcept
 Access to the internal atomic value.

Detailed Description

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

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

Template Parameters
TThe type of the value contained in the atomic_condition. Must be TriviallyCopyable, CopyConstructible and CopyAssignable.

Constructor & Destructor Documentation

◆ atomic_condition()

template<typename T>
coopsync_tbb::atomic_condition< T >::atomic_condition ( T value)
explicit

Constructs a new atomic_condition with the given initial value. This operation is not atomic.

Parameters
valueA value to move-construct the internal atomic from.

◆ ~atomic_condition()

template<typename T>
coopsync_tbb::atomic_condition< T >::~atomic_condition ( )

Destroys the atomic_condition.

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

Member Function Documentation

◆ atomic() [1/2]

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

Access to the internal atomic value.

Returns
Const reference to the internal atomic value. Remains valid for the lifetime of the atomic_condition.

◆ atomic() [2/2]

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

Access to the internal atomic value.

Returns
Reference to the internal atomic value. Remains valid for the lifetime of the atomic_condition.

◆ operator*() [1/2]

template<typename T>
const std::atomic< T > & coopsync_tbb::atomic_condition< T >::operator* ( ) const
noexcept

Access to the internal atomic value.

Returns
Const reference to the internal atomic value. Remains valid for the lifetime of the atomic_condition.

◆ operator*() [2/2]

template<typename T>
std::atomic< T > & coopsync_tbb::atomic_condition< T >::operator* ( )
noexcept

Access to the internal atomic value.

Returns
Reference to the internal atomic value. Remains valid for the lifetime of the atomic_condition.

◆ operator->() [1/2]

template<typename T>
const std::atomic< T > * coopsync_tbb::atomic_condition< T >::operator-> ( ) const
noexcept

Access to the internal atomic value.

Returns
Const pointer to the internal atomic value. Remains valid for the lifetime of the atomic_condition.

◆ operator->() [2/2]

template<typename T>
std::atomic< T > * coopsync_tbb::atomic_condition< T >::operator-> ( )
noexcept

Access to the internal atomic value.

Returns
Pointer to the internal atomic value. Remains valid for the lifetime of the atomic_condition.

◆ wait()

template<typename T>
void coopsync_tbb::atomic_condition< T >::wait ( value_type old,
std::memory_order order = std::memory_order_seq_cst )

Suspends the calling task until the internal atomic value is not equal to specified value. If the internal atomic value is not equal to old, the function returns immediately. Otherwise, the task is suspended. The task will be resumed once notify_one or notify_all is called and the internal atomic value is not equal to old.

Parameters
oldThe value to compare the internal atomic value to. The task will be suspended while the internal atomic value is equal to old.
orderThe memory order to use for loading the internal atomic 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 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: