13 explicit latch(std::ptrdiff_t count) : count_(count) {}
18 roo::lock_guard<roo::mutex> lock(mutex_);
19 if ((count_ -= n) == 0) {
26 roo::unique_lock<roo::mutex> lock(mutex_);
27 cv_.wait(lock, [
this] {
return count_ == 0; });
31 mutable roo::mutex mutex_;
32 mutable roo::condition_variable cv_;
33 std::ptrdiff_t count_;
A synchronization aid that blocks until a counter reaches zero.
void wait() const
Blocks until the internal counter reaches zero.
latch(std::ptrdiff_t count)
Creates a latch with an initial counter value.
void count_down(std::ptrdiff_t n=1)
Decrements the counter and wakes waiters when it reaches zero.