CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
AsyncLatch.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "AsyncManualResetEvent.hpp"
11
14
16
17namespace CeresEngine {
18
19 class AsyncLatch {
20 public:
29
33 bool is_ready() const noexcept { return mEvent.is_set(); }
34
47 void count_down(std::ptrdiff_t n = 1) noexcept {
48 if(mCount.fetch_sub(n, std::memory_order_acq_rel) <= n) {
49 mEvent.set();
50 }
51 }
52
59 auto operator co_await() const noexcept { return mEvent.operator co_await(); }
60
61 private:
64 };
65} // namespace CeresEngine
Definition AsyncLatch.hpp:19
bool is_ready() const noexcept
Query if the latch has become signalled.
Definition AsyncLatch.hpp:33
Atomic< std::ptrdiff_t > mCount
Definition AsyncLatch.hpp:62
AsyncLatch(std::ptrdiff_t initialCount) noexcept
Construct the latch with the specified initial count.
Definition AsyncLatch.hpp:28
AsyncManualResetEvent mEvent
Definition AsyncLatch.hpp:63
void count_down(std::ptrdiff_t n=1) noexcept
Decrement the count by n.
Definition AsyncLatch.hpp:47
An async manual-reset event is a coroutine synchronisation abstraction that allows one or more corout...
Definition AsyncEvent.hpp:27
void set() noexcept
Set the state of the event to 'set'.
Definition Application.hpp:19
std::atomic< T > Atomic
The Atomic template defines an atomic type.
Definition Atomic.hpp:16
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25