From 314bd2bb486adcf05ca9fe917fedcabff4b54492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 20 Nov 2017 15:57:31 +0100 Subject: [PATCH] Fix WinAPI condition for outOfWaiters event loop exit reason. Calling processEvents could previously block indefinitely even if there were no waiters left. --- source/eventcore/drivers/winapi/core.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/eventcore/drivers/winapi/core.d b/source/eventcore/drivers/winapi/core.d index a0b4179..ed89d7e 100644 --- a/source/eventcore/drivers/winapi/core.d +++ b/source/eventcore/drivers/winapi/core.d @@ -48,6 +48,8 @@ final class WinAPIEventDriverCore : EventDriverCore { return ExitReason.exited; } + if (!waiterCount) return ExitReason.outOfWaiters; + bool got_event; if (timeout <= 0.seconds) { @@ -109,7 +111,7 @@ final class WinAPIEventDriverCore : EventDriverCore { DWORD timeout_msecs = max_wait == Duration.max ? INFINITE : cast(DWORD)min(max_wait.total!"msecs", DWORD.max); auto ret = () @trusted { return MsgWaitForMultipleObjectsEx(cast(DWORD)m_registeredEvents.length, m_registeredEvents.ptr, timeout_msecs, QS_ALLEVENTS, MWMO_ALERTABLE|MWMO_INPUTAVAILABLE); } (); - + if (ret == WAIT_IO_COMPLETION) got_event = true; else if (ret >= WAIT_OBJECT_0 && ret < WAIT_OBJECT_0 + m_registeredEvents.length) { if (auto pc = m_registeredEvents[ret - WAIT_OBJECT_0] in m_eventCallbacks) {