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

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

Public Member Functions

 AsyncLatch (std::ptrdiff_t initialCount) noexcept
 Construct the latch with the specified initial count.
 
bool is_ready () const noexcept
 Query if the latch has become signalled.
 
void count_down (std::ptrdiff_t n=1) noexcept
 Decrement the count by n.
 
auto operator co_await () const noexcept
 Allows the latch to be awaited within a coroutine.
 

Private Attributes

Atomic< std::ptrdiff_t > mCount
 
AsyncManualResetEvent mEvent
 

Constructor & Destructor Documentation

◆ AsyncLatch()

CeresEngine::AsyncLatch::AsyncLatch ( std::ptrdiff_t  initialCount)
inlinenoexcept

Construct the latch with the specified initial count.

Parameters
initialCountThe initial count of the latch. The latch will become signalled once this->count_down() has been called initialCount times. The latch will be immediately signalled on construction if this parameter is zero or negative.

Member Function Documentation

◆ count_down()

void CeresEngine::AsyncLatch::count_down ( std::ptrdiff_t  n = 1)
inlinenoexcept

Decrement the count by n.

Any coroutines awaiting this latch will be resumed once the count reaches zero. ie. when this method has been called at least 'initialCount' times.

Any awaiting coroutines that are currently suspended waiting for the latch to become signalled will be resumed inside the last call to this method (ie. the call that decrements the count to zero).

Parameters
nThe amount to decrement the count by.

◆ is_ready()

bool CeresEngine::AsyncLatch::is_ready ( ) const
inlinenoexcept

Query if the latch has become signalled.

The latch is marked as signalled once the count reaches zero.

◆ operator co_await()

auto CeresEngine::AsyncLatch::operator co_await ( ) const
inlinenoexcept

Allows the latch to be awaited within a coroutine.

If the latch is already signalled (ie. the count has been decremented to zero) then the awaiting coroutine will continue without suspending. Otherwise, the coroutine will suspend and will later be resumed inside a call to count_down().

Member Data Documentation

◆ mCount

Atomic<std::ptrdiff_t> CeresEngine::AsyncLatch::mCount
private

◆ mEvent

AsyncManualResetEvent CeresEngine::AsyncLatch::mEvent
private

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