From 68f5cc1873e637df12ab03c5b43f6121c59dcb4f Mon Sep 17 00:00:00 2001 From: hrydgard Date: Sun, 22 Feb 2009 22:49:42 +0000 Subject: Attempt to workaround some stop hangs by using MsgWait instead of Wait. change order of dsp / video shutdown. some comments. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2379 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/Thread.cpp | 48 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'Source/Core/Common/Src/Thread.cpp') diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp index a5c4e53cc6..7057a137ac 100644 --- a/Source/Core/Common/Src/Thread.cpp +++ b/Source/Core/Common/Src/Thread.cpp @@ -133,18 +133,60 @@ void Event::Shutdown() m_hEvent = 0; } - - void Event::Set() { SetEvent(m_hEvent); } - void Event::Wait() { WaitForSingleObject(m_hEvent, INFINITE); } + +inline HRESULT MsgWaitForSingleObject(HANDLE handle, DWORD timeout) +{ + return MsgWaitForMultipleObjects(1, &handle, FALSE, timeout, 0); +} + +void Event::MsgWait() +{ + // Adapted from MSDN example http://msdn.microsoft.com/en-us/library/ms687060.aspx + while (true) + { + DWORD result; + MSG msg; + // Read all of the messages in this next loop, + // removing each message as we read it. + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + // If it is a quit message, exit. + if (msg.message == WM_QUIT) + return; + // Otherwise, dispatch the message. + DispatchMessage(&msg); + } + + // Wait for any message sent or posted to this queue + // or for one of the passed handles be set to signaled. + result = MsgWaitForSingleObject(m_hEvent, INFINITE); + + // The result tells us the type of event we have. + if (result == (WAIT_OBJECT_0 + 1)) + { + // New messages have arrived. + // Continue to the top of the always while loop to + // dispatch them and resume waiting. + continue; + } + else + { + // result == WAIT_OBJECT_0 + // Our event got signaled + return; + } + } +} + ///////////////////////////////////// -- cgit v1.2.3