blob: fb6374e773cf04764cafad373f8aa15c37020abb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#pragma once
#include <util/system/atomic.h>
#include <util/system/event.h>
class TCountDownLatch {
private:
TAtomic Current;
TSystemEvent EventObject;
public:
TCountDownLatch(unsigned initial)
: Current(initial)
{
}
void CountDown() {
if (AtomicDecrement(Current) == 0) {
EventObject.Signal();
}
}
void Await() {
EventObject.Wait();
}
bool Await(TDuration timeout) {
return EventObject.WaitT(timeout);
}
};
|