MCPcopy Create free account
hub / github.com/Inori/GPCS4 / Wait

Method Wait

GPCS4/SceModules/SceLibkernel/SceSemaphore.cpp:57–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57int CSceSemaphore::Wait(int count, uint32_t* pTimeOut)
58{
59 int err = SCE_KERNEL_ERROR_UNKNOWN;
60 std::unique_lock<std::mutex> lock(m_mutex);
61 do
62 {
63 if (count < 1 || count > m_maxCount)
64 {
65 err = SCE_KERNEL_ERROR_EINVAL;
66 break;
67 }
68
69 auto pred = [this, count] { return m_count >= count; };
70 if (!pTimeOut) // infinite
71 {
72 m_cond.wait(lock, pred);
73 m_count -= count;
74 }
75 else
76 {
77 auto timeMs = std::chrono::microseconds(*pTimeOut);
78 auto start = std::chrono::high_resolution_clock::now();
79
80 bool notExpired = m_cond.wait_for(lock, timeMs, pred);
81
82 auto end = std::chrono::high_resolution_clock::now();
83 if (notExpired)
84 {
85 auto dura = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
86 auto timeLeft = timeMs - dura;
87 *pTimeOut = timeLeft.count();
88 m_count -= count;
89 }
90 else
91 {
92 *pTimeOut = 0;
93 err = SCE_KERNEL_ERROR_ETIMEDOUT;
94 break;
95 }
96
97 }
98
99 err = SCE_OK;
100 } while (false);
101 return err;
102}
103
104// TODO:
105// implement Cancel

Callers 2

sceKernelWaitEventFlagFunction · 0.45
sceKernelWaitSemaFunction · 0.45

Calls 2

waitMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected