| 39 | } |
| 40 | |
| 41 | void CountdownEvent::signal(int sig, bool flush) { |
| 42 | // Have to save _butex, *this is probably defreferenced by the wait thread |
| 43 | // which sees fetch_sub |
| 44 | void* const saved_butex = _butex; |
| 45 | const int prev = ((butil::atomic<int>*)_butex) |
| 46 | ->fetch_sub(sig, butil::memory_order_release); |
| 47 | // DON'T touch *this ever after |
| 48 | if (prev > sig) { |
| 49 | return; |
| 50 | } |
| 51 | LOG_IF(ERROR, prev < sig) << "Counter is over decreased"; |
| 52 | butex_wake_all(saved_butex, flush); |
| 53 | } |
| 54 | |
| 55 | int CountdownEvent::wait() { |
| 56 | _wait_was_invoked = true; |