Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
uni20::async::EpochContextReader< T > Class Template Reference

RAII handle representing the writer of a value in an EpochContext. More...

#include <epoch_context.hpp>

Public Member Functions

T const & data () const
 Access the stored value inside the parent Async<T>.
 
T const * data_maybe () const
 
std::optional< T > data_option () const
 Optionally retrieves the value stored in this buffer, if available.
 
std::shared_ptr< EpochContext > epoch_context_shared () const noexcept
 
 EpochContextReader ()=delete
 Default-constructed inactive reader (no effect).
 
 EpochContextReader (EpochContextReader &&other) noexcept
 Move constructor.
 
 EpochContextReader (EpochContextReader const &other)
 Copy constructor retaining the reader reference count.
 
 EpochContextReader (shared_storage< T > storage, std::shared_ptr< EpochContext > epoch) noexcept
 Construct a new reader handle for a given parent and epoch.
 
T const & get_wait () const
 Wait for the epoch to become available on the global scheduler and return a reference to the value.
 
T const & get_wait (IAsyncScheduler &sched) const
 Wait for the epoch to become available on the provided scheduler and return a reference to the value.
 
void notify_when_ready (std::function< void()> notify) const
 Register a callback for this reader becoming ready.
 
EpochContextReader & operator= (EpochContextReader &&other) noexcept
 Move assignment.
 
EpochContextReader & operator= (EpochContextReader const &other)
 Copy assignment retaining the reader reference count.
 
bool ready () const noexcept
 Check whether the reader is ready to resume.
 
void release () noexcept
 Release the reader.
 
void suspend (BasicTask &&t)
 Suspend a coroutine task as a reader of this epoch.
 
void wait () const
 Wait for the epoch to become available on the global scheduler.
 
void wait (IAsyncScheduler &sched) const
 Wait for the epoch to become available on the provided scheduler.
 
 ~EpochContextReader ()
 Destructor. Signals epoch reader completion if still active.
 

Detailed Description

template<typename T>
class uni20::async::EpochContextReader< T >

RAII handle representing the writer of a value in an EpochContext.

On construction, this marks the epoch as having a writer. When the buffer is set and the writer releases the value, waiting readers may resume.

EpochContextWriter does not represent a coroutine or suspendable operation. It is a scoped object used to enforce single-writer discipline and ensure writer→readers sequencing.

Note
Writer must eventually call .release() to trigger reader advancement.
See also
EpochContext, EpochContextReader

Constructor & Destructor Documentation

◆ EpochContextReader() [1/4]

template<typename T >
uni20::async::EpochContextReader< T >::EpochContextReader ( )
delete

Default-constructed inactive reader (no effect).

◆ EpochContextReader() [2/4]

template<typename T >
uni20::async::EpochContextReader< T >::EpochContextReader ( EpochContextReader< T > const &  other)
inline

Copy constructor retaining the reader reference count.

◆ EpochContextReader() [3/4]

template<typename T >
uni20::async::EpochContextReader< T >::EpochContextReader ( shared_storage< T >  storage,
std::shared_ptr< EpochContext >  epoch 
)
inlinenoexcept

Construct a new reader handle for a given parent and epoch.

Parameters
valueShared pointer to the stored value.
epochPointer to the epoch being tracked.

◆ EpochContextReader() [4/4]

template<typename T >
uni20::async::EpochContextReader< T >::EpochContextReader ( EpochContextReader< T > &&  other)
inlinenoexcept

Move constructor.

Transfers ownership and nulls the source.

Parameters
otherReader being moved from.

◆ ~EpochContextReader()

template<typename T >
uni20::async::EpochContextReader< T >::~EpochContextReader ( )
inline

Destructor. Signals epoch reader completion if still active.

Member Function Documentation

◆ data()

template<typename T >
T const & uni20::async::EpochContextReader< T >::data ( ) const
inline

Access the stored value inside the parent Async<T>.

Returns
Reference to the T value.
Precondition
The value must be ready. Should only be called after await_ready() returns true.
Exceptions
buffer_read_uninitializedif no value was constructed for this epoch.

◆ data_maybe()

template<typename T >
T const * uni20::async::EpochContextReader< T >::data_maybe ( ) const
inline
Returns
A pointer to the value, if it is written, otherwise returns nullptr.
Exceptions
Anyexception stored in the writer, if the buffer is in an exception state.
Precondition
The buffer must be ready for reading (i.e., the write gate is closed).

◆ data_option()

template<typename T >
std::optional< T > uni20::async::EpochContextReader< T >::data_option ( ) const
inline

Optionally retrieves the value stored in this buffer, if available.

Returns
A copy of the value if it was written; std::nullopt if the buffer was cancelled.
Exceptions
Anyexception stored in the writer, if the write failed exceptionally.
Precondition
The buffer must be ready for reading (i.e., the write gate is closed).
Postcondition
If a value is returned, it is a full copy and independent of the internal buffer.

◆ epoch_context_shared()

template<typename T >
std::shared_ptr< EpochContext > uni20::async::EpochContextReader< T >::epoch_context_shared ( ) const
inlinenoexcept

◆ get_wait() [1/2]

template<typename T >
T const & uni20::async::EpochContextReader< T >::get_wait ( ) const

Wait for the epoch to become available on the global scheduler and return a reference to the value.

Wait for a reader context using the global scheduler.

Template Parameters
TStored value type.
Returns
Reference to the ready value.

◆ get_wait() [2/2]

template<typename T >
T const & uni20::async::EpochContextReader< T >::get_wait ( IAsyncScheduler &  sched) const

Wait for the epoch to become available on the provided scheduler and return a reference to the value.

Wait for a reader context using an explicit scheduler.

Parameters
schedScheduler used to drive readiness.
Template Parameters
TStored value type.
Parameters
schedScheduler used to drive progress.
Returns
Reference to the ready value.

◆ notify_when_ready()

template<typename T >
void uni20::async::EpochContextReader< T >::notify_when_ready ( std::function< void()>  notify) const
inline

Register a callback for this reader becoming ready.

Parameters
notifyNon-throwing callback invoked when the epoch reaches Reading.

◆ operator=() [1/2]

template<typename T >
EpochContextReader & uni20::async::EpochContextReader< T >::operator= ( EpochContextReader< T > &&  other)
inlinenoexcept

Move assignment.

Releases prior ownership and transfers.

Parameters
otherReader being moved from.
Returns
Reference to *this after transfer.

◆ operator=() [2/2]

template<typename T >
EpochContextReader & uni20::async::EpochContextReader< T >::operator= ( EpochContextReader< T > const &  other)
inline

Copy assignment retaining the reader reference count.

Parameters
otherReader being copied from.
Returns
Reference to *this after copy.

◆ ready()

template<typename T >
bool uni20::async::EpochContextReader< T >::ready ( ) const
inlinenoexcept

Check whether the reader is ready to resume.

Returns
True if all prerequisites for this epoch are satisfied.

◆ release()

template<typename T >
void uni20::async::EpochContextReader< T >::release ( )
inlinenoexcept

Release the reader.

◆ suspend()

template<typename T >
void uni20::async::EpochContextReader< T >::suspend ( BasicTask &&  t)
inline

Suspend a coroutine task as a reader of this epoch.

Parameters
tThe coroutine task to register.

◆ wait() [1/2]

template<typename T >
void uni20::async::EpochContextReader< T >::wait ( ) const

Wait for the epoch to become available on the global scheduler.

Wait for a reader context using the global scheduler.

Template Parameters
TStored value type.

◆ wait() [2/2]

template<typename T >
void uni20::async::EpochContextReader< T >::wait ( IAsyncScheduler &  sched) const

Wait for the epoch to become available on the provided scheduler.

Wait for a reader context using an explicit scheduler.

Parameters
schedScheduler used to drive readiness.
Template Parameters
TStored value type.
Parameters
schedScheduler used to drive progress.

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