CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::SingleConsumerEvent Class Reference

A manual-reset event that supports only a single awaiting coroutine at a time. More...

#include <CeresEngine/Foundation/Threading/AsyncEvent.hpp>

Public Member Functions

 SingleConsumerEvent (const bool initiallySet=false) noexcept
 Construct a new event, initialising to either 'set' or 'not set' state.
 
bool is_set () const noexcept
 Query if this event has been set.
 
void set ()
 Transition this event to the 'set' state if it is not already set.
 
void reset () noexcept
 Transition this event to the 'non set' state if it was in the set state.
 
auto operator co_await () noexcept
 Wait until the event becomes set.
 

Private Types

enum class  state { not_set , not_set_consumer_waiting , set }
 

Private Attributes

Atomic< statemState
 
CoroutineHandle mAwaiter
 

Detailed Description

A manual-reset event that supports only a single awaiting coroutine at a time.

You can co_await the event to suspend the current coroutine until some thread calls set(). If the event is already set then the coroutine will not be suspended and will continue execution. If the event was not yet set then the coroutine will be resumed on the thread that calls set() within the call to set().

Callers must ensure that only one coroutine is executing a co_await statement at any point in time.

Member Enumeration Documentation

◆ state

Enumerator
not_set 
not_set_consumer_waiting 
set 

Constructor & Destructor Documentation

◆ SingleConsumerEvent()

CeresEngine::SingleConsumerEvent::SingleConsumerEvent ( const bool  initiallySet = false)
inlinenoexcept

Construct a new event, initialising to either 'set' or 'not set' state.

Parameters
initiallySetIf true then initialises the event to the 'set' state. Otherwise, initialised the event to the 'not set' state.

Member Function Documentation

◆ is_set()

bool CeresEngine::SingleConsumerEvent::is_set ( ) const
inlinenoexcept

Query if this event has been set.

◆ operator co_await()

auto CeresEngine::SingleConsumerEvent::operator co_await ( )
inlinenoexcept

Wait until the event becomes set.

If the event is already set then the awaiting coroutine will not be suspended and will continue execution. If the event was not yet set then the coroutine will be suspended and will be later resumed inside a subsequent call to set() on the thread that calls set().

◆ reset()

void CeresEngine::SingleConsumerEvent::reset ( )
inlinenoexcept

Transition this event to the 'non set' state if it was in the set state.

◆ set()

void CeresEngine::SingleConsumerEvent::set ( )
inline

Transition this event to the 'set' state if it is not already set.

If there was a coroutine awaiting the event then it will be resumed inside this call.

Member Data Documentation

◆ mAwaiter

CoroutineHandle CeresEngine::SingleConsumerEvent::mAwaiter
private

◆ mState

Atomic<state> CeresEngine::SingleConsumerEvent::mState
private

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