Change retire strategy in cond_variable::imp_wait (WIN32)

Instead of waiting infinitely, try and yield until success
This commit is contained in:
Nekotekina 2018-05-17 21:29:49 +03:00
parent 39088e5005
commit 0b1c8bc676

View file

@ -21,9 +21,17 @@ bool cond_variable::imp_wait(u32 _old, u64 _timeout) noexcept
verify(HERE), rc == WAIT_TIMEOUT;
// Retire
if (!m_value.fetch_op([](u32& value) { if (value) value--; }))
while (!m_value.fetch_op([](u32& value) { if (value) value--; }))
{
NtWaitForKeyedEvent(nullptr, &m_value, false, nullptr);
timeout.QuadPart = 0;
if (HRESULT rc2 = NtWaitForKeyedEvent(nullptr, &m_value, false, &timeout))
{
verify(HERE), rc2 == WAIT_TIMEOUT;
SwitchToThread();
continue;
}
return true;
}