blob: 14e344365edf2fe8e5a3d4e72f6c6a8220c94c7f (
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
37
38
39
40
41
42
|
#pragma once
#include "public.h"
#ifndef _linux_
#include <util/system/condvar.h>
#include <util/system/mutex.h>
#endif
namespace NYT::NThreading {
////////////////////////////////////////////////////////////////////////////////
//! A synchronization aid that allows one or more threads to wait until
//! a set of operations being performed in other threads completes.
/*!
* See https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CountDownLatch.html
*/
class TCountDownLatch final
{
public:
explicit TCountDownLatch(int count);
void CountDown();
void Wait() const;
bool TryWait() const;
int GetCount() const;
private:
std::atomic<int> Count_;
#ifndef _linux_
mutable TCondVar ConditionVariable_;
mutable TMutex Mutex_;
#endif
};
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NThreading
|