From 2bec3bf3acca6ba235cd774e3244c2bc009e3a89 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Feb 2018 16:12:33 -0800 Subject: [PATCH] Windows: Trigger StopThread() on shutdown. Otherwise, we end up hanging in the loop waiting for emuThreadState to become STOPPED. It actually has, but ThreadFrame() will block until a new frame is queued... while will never happen, because the emuthread has stopped. --- Common/GraphicsContext.h | 1 + Windows/EmuThread.cpp | 3 +++ Windows/GPU/WindowsGLContext.cpp | 5 +++++ Windows/GPU/WindowsGLContext.h | 1 + 4 files changed, 10 insertions(+) diff --git a/Common/GraphicsContext.h b/Common/GraphicsContext.h index 66afcd94da..5dfec7f6d9 100644 --- a/Common/GraphicsContext.h +++ b/Common/GraphicsContext.h @@ -32,6 +32,7 @@ public: virtual void ThreadStart() {} virtual bool ThreadFrame() { return true; } virtual void ThreadEnd() {} + virtual void StopThread() {} virtual Draw::DrawContext *GetDrawContext() = 0; }; diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 5b9d1faca5..4e18eb1f53 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -86,6 +86,9 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) { emuThreadState = (int)EmuThreadState::STOPPED; NativeShutdownGraphics(); + + // Ask the main thread to stop. This prevents a hang on a race condition. + graphicsContext->StopThread(); } static void EmuThreadStart(GraphicsContext *graphicsContext) { diff --git a/Windows/GPU/WindowsGLContext.cpp b/Windows/GPU/WindowsGLContext.cpp index 7962d3a817..b5dfc831d0 100644 --- a/Windows/GPU/WindowsGLContext.cpp +++ b/Windows/GPU/WindowsGLContext.cpp @@ -432,3 +432,8 @@ bool WindowsGLContext::ThreadFrame() { void WindowsGLContext::ThreadEnd() { renderManager_->ThreadEnd(); } + +void WindowsGLContext::StopThread() { + renderManager_->WaitUntilQueueIdle(); + renderManager_->StopThread(); +} diff --git a/Windows/GPU/WindowsGLContext.h b/Windows/GPU/WindowsGLContext.h index 38c9494947..1303aece79 100644 --- a/Windows/GPU/WindowsGLContext.h +++ b/Windows/GPU/WindowsGLContext.h @@ -29,6 +29,7 @@ public: void ThreadStart() override; void ThreadEnd() override; bool ThreadFrame() override; + void StopThread() override; Draw::DrawContext *GetDrawContext() override { return draw_; }