| 41 | } |
| 42 | |
| 43 | void Threading::WorkSema::WaitForWork() |
| 44 | { |
| 45 | // State change: |
| 46 | // SLEEPING, SPINNING: This is the worker thread and it's clearly not asleep or spinning, so these states should be impossible |
| 47 | // RUNNING_0: Change state to SLEEPING, wake up thread if WAITING_EMPTY |
| 48 | // RUNNING_N: Change state to RUNNING_0 (and preserve WAITING_EMPTY flag) |
| 49 | s32 value = m_state.load(std::memory_order_relaxed); |
| 50 | pxAssert(!IsDead(value)); |
| 51 | while (!m_state.compare_exchange_weak(value, NextStateWaitForWork(value), std::memory_order_acq_rel, std::memory_order_relaxed)) |
| 52 | ; |
| 53 | if (IsReadyForSleep(value)) |
| 54 | { |
| 55 | if (value & STATE_FLAG_WAITING_EMPTY) |
| 56 | m_empty_sema.Post(); |
| 57 | m_sema.Wait(); |
| 58 | // Acknowledge any additional work added between wake up request and getting here |
| 59 | m_state.fetch_and(STATE_FLAG_WAITING_EMPTY, std::memory_order_acquire); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void Threading::WorkSema::WaitForWorkWithSpin() |
| 64 | { |
no test coverage detected