-
Notifications
You must be signed in to change notification settings - Fork 6
/
countdownlatch.hpp
51 lines (41 loc) · 1.34 KB
/
countdownlatch.hpp
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
43
44
45
46
47
48
49
50
51
#ifndef __COUNTDOWNLATCH_NIPUN__
#define __COUNTDOWNLATCH_NIPUN__
#include <inttypes.h>
#include <stdint.h>
#include <mutex>
#include <condition_variable>
namespace clatch
{
class countdownlatch {
public:
/*! Constructor
\param count, the value the countdownlatch object should be initialized with
*/
countdownlatch(uint32_t count);
/*!
await causes the caller to wait until the latch is counted down to zero,
if wait time nanosecs is not zero, then maximum wait is for nanosec nanoseconds
\param nanosecs is waittime in nanoseconds, by default it is zero which specifies
indefinite wait
*/
void await(uint64_t nanosecs=0);
/*!
Countdown decrements the count of the latch, signalling all waiting thread if the
count reaches zero.
*/
void count_down();
/*!
get_count returns the current count
*/
uint32_t get_count();
private:
std::condition_variable cv;
std::mutex lock;
uint32_t count;
// deleted constructors/assignmenet operators
countdownlatch() = delete;
countdownlatch(const countdownlatch& other) = delete;
countdownlatch& operator=(const countdownlatch& opther) = delete;
};
}
#endif