blob: 34ec9331840e17f03bd5d028979f9ad6ebb24dc2 (
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
31
32
33
34
35
36
|
#pragma once
#include "latch.h"
template <typename TThis>
class TComplexConditionSemaphore {
private:
TLatch Latch;
public:
void Updated() {
if (GetThis()->TryWait()) {
Latch.Unlock();
}
}
void Wait() {
while (!GetThis()->TryWait()) {
Latch.Lock();
if (GetThis()->TryWait()) {
Latch.Unlock();
return;
}
Latch.Wait();
}
}
bool IsLocked() {
return Latch.IsLocked();
}
private:
TThis* GetThis() {
return static_cast<TThis*>(this);
}
};
|