MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / CheckForWork

Method CheckForWork

common/Semaphore.cpp:18–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16// --------------------------------------------------------------------------------------
17
18bool 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
43void Threading::WorkSema::WaitForWork()
44{

Callers 1

MainLoopMethod · 0.80

Calls 2

loadMethod · 0.45
PostMethod · 0.45

Tested by

no test coverage detected