diff --git a/Core/Core.cpp b/Core/Core.cpp index 7bb1db314f..3c5bb47ae1 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -144,6 +144,14 @@ bool Core_IsInactive() { return coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME && !coreStatePending; } +static inline void Core_StateProcessed() { + if (coreStatePending) { + std::lock_guard guard(m_hInactiveMutex); + coreStatePending = false; + m_InactiveCond.notify_all(); + } +} + void Core_WaitInactive() { while (Core_IsActive() && !GPUStepping::IsStepping()) { std::unique_lock guard(m_hInactiveMutex); @@ -219,21 +227,11 @@ bool UpdateScreenScale(int width, int height) { } // Used by Windows, SDL, Qt. -void UpdateRunLoop(GraphicsContext *ctx) { - NativeFrame(ctx); - if (windowHidden && g_Config.bPauseWhenMinimized) { - sleep_ms(16, "window-hidden"); - return; - } -} - -// Note: not used on Android. void Core_RunLoop(GraphicsContext *ctx) { if (windowHidden && g_Config.bPauseWhenMinimized) { sleep_ms(16, "window-hidden"); return; } - NativeFrame(ctx); } @@ -338,7 +336,7 @@ static void Core_PerformStep(MIPSDebugInterface *cpu, CPUStepType stepType, int } void Core_ProcessStepping(MIPSDebugInterface *cpu) { - coreStatePending = false; + Core_StateProcessed(); // Check if there's any pending save state actions. SaveState::Process(); @@ -387,6 +385,7 @@ bool Core_Run(GraphicsContext *ctx) { System_Notify(SystemNotification::DISASSEMBLY); while (true) { if (GetUIState() != UISTATE_INGAME) { + Core_StateProcessed(); if (GetUIState() == UISTATE_EXIT) { // Not sure why we do a final frame here? NativeFrame(ctx); @@ -405,9 +404,12 @@ bool Core_Run(GraphicsContext *ctx) { return true; } break; + case CORE_POWERDOWN: + // Need to step the loop. + Core_RunLoop(ctx); + return true; case CORE_POWERUP: - case CORE_POWERDOWN: case CORE_BOOT_ERROR: case CORE_RUNTIME_ERROR: // Exit loop!! diff --git a/Core/Core.h b/Core/Core.h index 7c8886304a..3ae8385434 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -25,8 +25,7 @@ class GraphicsContext; -// called from emu thread -void UpdateRunLoop(GraphicsContext *ctx); +void Core_RunLoop(GraphicsContext *ctx); // For platforms that don't call Core_Run void Core_SetGraphicsContext(GraphicsContext *ctx); diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 2f789effe9..5452b0f664 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -482,7 +482,7 @@ void MainUI::EmuThreadFunc() { emuThreadState = (int)EmuThreadState::RUNNING; while (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED) { updateAccelerometer(); - UpdateRunLoop(graphicsContext); + Core_RunLoop(graphicsContext); } emuThreadState = (int)EmuThreadState::STOPPED; @@ -726,7 +726,7 @@ void MainUI::paintGL() { #endif updateAccelerometer(); if (emuThreadState == (int)EmuThreadState::DISABLED) { - UpdateRunLoop(graphicsContext); + Core_RunLoop(graphicsContext); } else { graphicsContext->ThreadFrame(); // Do the rest in EmuThreadFunc diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 4937cd2ace..85b5ac6170 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -695,7 +695,7 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) { NativeInitGraphics(graphicsContext); while (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED) { - UpdateRunLoop(graphicsContext); + Core_RunLoop(graphicsContext); } emuThreadState = (int)EmuThreadState::STOPPED; graphicsContext->StopThread(); @@ -1535,7 +1535,7 @@ int main(int argc, char *argv[]) { if (g_QuitRequested || g_RestartRequested) break; if (emuThreadState == (int)EmuThreadState::DISABLED) { - UpdateRunLoop(graphicsContext); + Core_RunLoop(graphicsContext); } if (g_QuitRequested || g_RestartRequested) break;