| 16 | // -------------------------------------------------------------------------------------- |
| 17 | |
| 18 | bool Threading::WorkSema::CheckForWork() |
| 19 | { |
| 20 | s32 value = m_state.load(std::memory_order_relaxed); |
| 21 | pxAssert(!IsDead(value)); |
| 22 | |
| 23 | // we want to switch to the running state, but preserve the waiting empty bit for RUNNING_N -> RUNNING_0 |
| 24 | // otherwise, we clear the waiting flag (since we're notifying the waiter that we're empty below) |
| 25 | while (!m_state.compare_exchange_weak(value, |
| 26 | IsReadyForSleep(value) ? STATE_RUNNING_0 : (value & STATE_FLAG_WAITING_EMPTY), |
| 27 | std::memory_order_acq_rel, std::memory_order_relaxed)) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | // if we're not empty, we have work to do |
| 32 | if (!IsReadyForSleep(value)) |
| 33 | return true; |
| 34 | |
| 35 | // this means we're empty, so notify any waiters |
| 36 | if (value & STATE_FLAG_WAITING_EMPTY) |
| 37 | m_empty_sema.Post(); |
| 38 | |
| 39 | // no work to do |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | void Threading::WorkSema::WaitForWork() |
| 44 | { |