Prewait prepares for waiting. After calling Prewait, the thread must re-check the wait predicate and then call either CancelWait or CommitWait.
| 66 | // After calling Prewait, the thread must re-check the wait predicate |
| 67 | // and then call either CancelWait or CommitWait. |
| 68 | void Prewait() { |
| 69 | uint64_t state = state_.load(std::memory_order_relaxed); |
| 70 | for (;;) { |
| 71 | CheckState(state); |
| 72 | uint64_t newstate = state + kWaiterInc; |
| 73 | CheckState(newstate); |
| 74 | if (state_.compare_exchange_weak(state, newstate, |
| 75 | std::memory_order_seq_cst)) |
| 76 | return; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // CommitWait commits waiting after Prewait. |
| 81 | void CommitWait(Waiter* w) { |