summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Src/Thread.cpp
diff options
context:
space:
mode:
authorhrydgard <hrydgard@gmail.com>2009-02-22 22:49:42 +0000
committerhrydgard <hrydgard@gmail.com>2009-02-22 22:49:42 +0000
commit68f5cc1873e637df12ab03c5b43f6121c59dcb4f (patch)
treebc57798285d6784cb87dfcec21c905461b2a4fd9 /Source/Core/Common/Src/Thread.cpp
parenta32e29aaa55da1a679223fe9e4153c2a2b5cdc33 (diff)
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
Diffstat (limited to 'Source/Core/Common/Src/Thread.cpp')
-rw-r--r--Source/Core/Common/Src/Thread.cpp48
1 files changed, 45 insertions, 3 deletions
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;
+ }
+ }
+}
+
/////////////////////////////////////