| 75 | } |
| 76 | |
| 77 | void WaitForNotification() const { |
| 78 | while (true) { |
| 79 | auto s = base::subtle::Acquire_Load(&state_); |
| 80 | if (s == NOT_NOTIFIED_NO_WAITERS) { |
| 81 | s = base::subtle::Acquire_CompareAndSwap( |
| 82 | &state_, NOT_NOTIFIED_NO_WAITERS, NOT_NOTIFIED_HAS_WAITERS); |
| 83 | if (s == NOT_NOTIFIED_NO_WAITERS) { |
| 84 | // We succeeded in the CAS -- sets 's' to be the new value of the |
| 85 | // state rather than the previous value. |
| 86 | s = NOT_NOTIFIED_HAS_WAITERS; |
| 87 | } |
| 88 | } |
| 89 | if (s == NOTIFIED) return; |
| 90 | DCHECK_EQ(s, NOT_NOTIFIED_HAS_WAITERS); |
| 91 | sys_futex(&state_, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, NOT_NOTIFIED_HAS_WAITERS, |
| 92 | /* timeout */ nullptr, nullptr /* ignored */, 0 /* ignored */); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void Notify() { |
| 97 | auto s = base::subtle::Release_AtomicExchange(&state_, NOTIFIED); |