MCPcopy Create free account
hub / github.com/3rdparty/libprocess / CountDownLatch

Class CountDownLatch

include/process/count_down_latch.hpp:24–50  ·  view source on GitHub ↗

An implementation of a count down latch that returns a Future to signify when it gets triggered.

Source from the content-addressed store, hash-verified

22// An implementation of a count down latch that returns a Future to
23// signify when it gets triggered.
24class CountDownLatch
25{
26public:
27 CountDownLatch(size_t count = 1) : count(count) {}
28
29 void decrement()
30 {
31 size_t expected = count.load();
32 while (expected > 0) {
33 if (count.compare_exchange_strong(expected, expected - 1)) {
34 if (expected == 1) {
35 promise.set(Nothing());
36 }
37 break;
38 }
39 }
40 }
41
42 Future<Nothing> triggered()
43 {
44 return promise.future();
45 }
46
47private:
48 std::atomic<size_t> count;
49 Promise<Nothing> promise;
50};
51
52} // namespace process {
53

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected