| 92 | } |
| 93 | |
| 94 | bool Threading::WorkSema::WaitForEmpty() |
| 95 | { |
| 96 | s32 value = m_state.load(std::memory_order_acquire); |
| 97 | while (true) |
| 98 | { |
| 99 | if (value < 0) |
| 100 | return !IsDead(value); // STATE_SLEEPING or STATE_SPINNING, queue is empty! |
| 101 | // Note: We technically only need memory_order_acquire on *failure* (because that's when we could leave without sleeping), but libstdc++ still asserts on failure < success |
| 102 | if (m_state.compare_exchange_weak(value, value | STATE_FLAG_WAITING_EMPTY, std::memory_order_acquire)) |
| 103 | break; |
| 104 | } |
| 105 | pxAssertMsg(!(value & STATE_FLAG_WAITING_EMPTY), "Multiple threads attempted to wait for empty (not currently supported)"); |
| 106 | m_empty_sema.Wait(); |
| 107 | return !IsDead(m_state.load(std::memory_order_relaxed)); |
| 108 | } |
| 109 | |
| 110 | bool Threading::WorkSema::WaitForEmptyWithSpin() |
| 111 | { |