From cdf378d20c2fd5891f69043046e2908eaae447e0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Feb 2018 11:40:11 -0800 Subject: [PATCH] GLES: Prevent race condition on shutdown. emuThreadState might become STOPPED before the last frame has been run, which can cause WaitUntilQueueIdle to hang. It's simpler just to wait until StopThread() is called, since it now is. This will line up properly with run_. --- Qt/QtMain.cpp | 4 ++-- SDL/SDLMain.cpp | 4 ++-- Windows/EmuThread.cpp | 4 ++-- android/jni/app-android.cpp | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index a2596d1368..297a31c661 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -248,9 +248,9 @@ MainUI::~MainUI() if (emuThreadState != (int)EmuThreadState::DISABLED) { ILOG("EmuThreadStop"); EmuThreadStop(); - while (emuThreadState != (int)EmuThreadState::STOPPED) { + while (graphicsContext->ThreadFrame()) { // Need to keep eating frames to allow the EmuThread to exit correctly. - graphicsContext->ThreadFrame(); + continue; } EmuThreadJoin(); } diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index bdc6c6d973..9cd5af04a9 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -896,9 +896,9 @@ int main(int argc, char *argv[]) { if (useEmuThread) { EmuThreadStop(); - while (emuThreadState != (int)EmuThreadState::STOPPED) { + while (graphicsContext->ThreadFrame()) { // Need to keep eating frames to allow the EmuThread to exit correctly. - graphicsContext->ThreadFrame(); + continue; } EmuThreadJoin(); } diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index b211783f6a..27a34fcc7b 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -244,9 +244,9 @@ void MainThreadFunc() { if (useEmuThread) { EmuThreadStop(); - while (emuThreadState != (int)EmuThreadState::STOPPED) { + while (graphicsContext->ThreadFrame()) { // Need to keep eating frames to allow the EmuThread to exit correctly. - graphicsContext->ThreadFrame(); + continue; } EmuThreadJoin(); } diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 2bf386e315..747629bde6 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -511,8 +511,8 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_pause(JNIEnv *, jclass) { extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) { if (useCPUThread && graphicsContext) { EmuThreadStop(); - while (emuThreadState != (int)EmuThreadState::STOPPED) { - graphicsContext->ThreadFrame(); + while (graphicsContext->ThreadFrame()) { + continue; } EmuThreadJoin(); } @@ -546,8 +546,8 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env, graphicsContext->ThreadEnd(); if (useCPUThread) { EmuThreadStop(); - while (emuThreadState != (int)EmuThreadState::STOPPED) { - graphicsContext->ThreadFrame(); + while (graphicsContext->ThreadFrame()) { + continue; } EmuThreadJoin(); } else {