From 5f4d304ebc887f60792b8ea4738564f3478bcc1f Mon Sep 17 00:00:00 2001 From: John Peterson Date: Tue, 24 Feb 2009 03:03:11 +0000 Subject: [PATCH] Threads and Stop: How about this? A timeout only for the shutdown process? That way the shutdown can either work anyway, or crash, which is simpler than having to open the Task Manager and manually end the deadlocked process. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2401 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/Thread.cpp | 4 ++-- Source/Core/Common/Src/Thread.h | 2 +- Source/Core/Core/Src/Core.cpp | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp index b7d185284d..72d56b17e1 100644 --- a/Source/Core/Common/Src/Thread.cpp +++ b/Source/Core/Common/Src/Thread.cpp @@ -87,11 +87,11 @@ Thread::~Thread() WaitForDeath(); } -void Thread::WaitForDeath() +void Thread::WaitForDeath(const int _Wait) { if (m_hThread) { - WaitForSingleObject(m_hThread, INFINITE); + WaitForSingleObject(m_hThread, _Wait); CloseHandle(m_hThread); m_hThread = NULL; } diff --git a/Source/Core/Common/Src/Thread.h b/Source/Core/Common/Src/Thread.h index 820eef78fe..10bbfdcbd9 100644 --- a/Source/Core/Common/Src/Thread.h +++ b/Source/Core/Common/Src/Thread.h @@ -74,9 +74,9 @@ public: void SetAffinity(int mask); static void SetCurrentThreadAffinity(int mask); + void WaitForDeath(const int _Wait = INFINITE); private: - void WaitForDeath(); #ifdef _WIN32 HANDLE m_hThread; diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index 5a04722434..e9dee8c17a 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -302,6 +302,7 @@ void Stop() if (GetParent((HWND)g_pWindowHandle) == NULL) #endif #ifndef SETUP_TIMER_WAITING // This is moved + g_EmuThread->WaitForDeath(5000); delete g_EmuThread; // Wait for emuthread to close. g_EmuThread = 0; #endif @@ -574,6 +575,7 @@ void EmuThreadEnd() if (cpuThread) { // There is a CPU thread - join it. + cpuThread->WaitForDeath(5000); delete cpuThread; // Returns after game exited cpuThread = NULL;