MCPcopy Create free account
hub / github.com/acl-dev/acl / add

Method add

lib_fiber/cpp/src/wait_group.cpp:18–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18void wait_group::add(int n)
19{
20 long long state = state_.add_fetch((long long)n << 32);
21
22 // The high 32 bits store the number of tasks.
23 int c = (int)(state >> 32);
24
25 // The low 32 bits store the number of waiters.
26 unsigned w = (unsigned)state;
27
28 // count must be >= 0.
29 if (c < 0){
30 logger_fatal("Negative wait_group counter, c=%d", c);
31 }
32
33 if (w != 0 && n > 0 && c == n){
34 logger_fatal("Add called concurrently with wait");
35 }
36
37 if (c > 0 || w == 0) {
38 return;
39 }
40
41 // Check if the state has been changed.
42 if (state_ != state) {
43 logger_fatal("Add called concurrently with wait");
44 }
45
46 // The count should be zero, so clear state and wakeup all the waiters.
47 state_ = 0;
48
49 for (size_t i = 0; i < w; i++) {
50#ifdef _DEBUG
51 unsigned long* tid = new unsigned long;
52 *tid = acl::thread::self();
53 box_->push(tid);
54#else
55 box_->push(NULL);
56#endif
57 }
58}
59
60void wait_group::done()
61{

Callers 7

fiber_createMethod · 0.45
event_defer_r_mergeFunction · 0.45
event_defer_w_mergeFunction · 0.45
event_addFunction · 0.45
IuFunction · 0.45
hvigor-wrapper.jsFile · 0.45
gaFunction · 0.45

Calls 3

add_fetchMethod · 0.80
selfFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected