Wait for the specified time, return false iff the count has not dropped to zero before the timeout expired.
| 56 | // Wait for the specified time, return false iff the count has not dropped to |
| 57 | // zero before the timeout expired. |
| 58 | inline bool WaitFor(std::chrono::milliseconds ms) { |
| 59 | unsigned int v = state_.fetch_or(1, std::memory_order_acq_rel); |
| 60 | if ((v >> 1) == 0) return true; |
| 61 | mutex_lock l(mu_); |
| 62 | while (!notified_) { |
| 63 | const std::cv_status status = cond_var_.wait_for(l, ms); |
| 64 | if (status == std::cv_status::timeout) { |
| 65 | return false; |
| 66 | } |
| 67 | } |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | mutex mu_; |