File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
#define __const__
3
+ #include < atomic>
3
4
#include " common/config.h"
4
5
#include " common/pp.h"
5
6
#include " common/syntax_helper.h"
@@ -71,3 +72,29 @@ typedef ::co::CoTimer::TimerId co_timer_id;
71
72
#define co_last_defer () ::co::GetLastDefer()
72
73
#define co_defer_scope co_defer [&]
73
74
75
+ class CountDownLatch {
76
+ public:
77
+ explicit CountDownLatch (size_t n = 1 ) : mFlyingCount(n) {}
78
+
79
+ void Add (size_t i) {
80
+ mFlyingCount += i;
81
+ }
82
+
83
+ void Done () {
84
+ if (--mFlyingCount == 0 ) {
85
+ ch_0.Close ();
86
+ }
87
+ }
88
+ void Wait () {
89
+ int done;
90
+ ch_0 >> done;
91
+ }
92
+ private:
93
+ std::atomic<size_t > mFlyingCount ;
94
+ co_chan<int > ch_0;
95
+
96
+ CountDownLatch (CountDownLatch const &) = delete ;
97
+ CountDownLatch (CountDownLatch &&) = delete ;
98
+ CountDownLatch& operator =(CountDownLatch const &) = delete ;
99
+ CountDownLatch& operator =(CountDownLatch &&) = delete ;
100
+ };
You can’t perform that action at this time.
0 commit comments