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

Method WaitForWork

common/Semaphore.cpp:43–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void 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
63void Threading::WorkSema::WaitForWorkWithSpin()
64{

Callers 3

ThreadEntryPointMethod · 0.80
MainLoopMethod · 0.80
ExecuteRingBufferMethod · 0.80

Calls 3

loadMethod · 0.45
PostMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected