From 0b1c8bc6766c65d66e503f806f287333ad6d465d Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 17 May 2018 21:29:49 +0300 Subject: [PATCH] Change retire strategy in cond_variable::imp_wait (WIN32) Instead of waiting infinitely, try and yield until success --- Utilities/cond.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Utilities/cond.cpp b/Utilities/cond.cpp index b9cddf5af1..260a01474f 100644 --- a/Utilities/cond.cpp +++ b/Utilities/cond.cpp @@ -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; }