CommitWait commits waiting after Prewait.
| 79 | |
| 80 | // CommitWait commits waiting after Prewait. |
| 81 | void CommitWait(Waiter* w) { |
| 82 | eigen_plain_assert((w->epoch & ~kEpochMask) == 0); |
| 83 | w->state = Waiter::kNotSignaled; |
| 84 | const uint64_t me = (w - &waiters_[0]) | w->epoch; |
| 85 | uint64_t state = state_.load(std::memory_order_seq_cst); |
| 86 | for (;;) { |
| 87 | CheckState(state, true); |
| 88 | uint64_t newstate; |
| 89 | if ((state & kSignalMask) != 0) { |
| 90 | // Consume the signal and return immediately. |
| 91 | newstate = state - kWaiterInc - kSignalInc; |
| 92 | } else { |
| 93 | // Remove this thread from pre-wait counter and add to the waiter stack. |
| 94 | newstate = ((state & kWaiterMask) - kWaiterInc) | me; |
| 95 | w->next.store(state & (kStackMask | kEpochMask), |
| 96 | std::memory_order_relaxed); |
| 97 | } |
| 98 | CheckState(newstate); |
| 99 | if (state_.compare_exchange_weak(state, newstate, |
| 100 | std::memory_order_acq_rel)) { |
| 101 | if ((state & kSignalMask) == 0) { |
| 102 | w->epoch += kEpochInc; |
| 103 | Park(w); |
| 104 | } |
| 105 | return; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // CancelWait cancels effects of the previous Prewait call. |
| 111 | void CancelWait() { |
no test coverage detected