diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 513ab4d4e1..0d6e04b134 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -428,6 +428,10 @@ void __IoManagerThread() { } } +void __IoWakeManager() { + ioManager.FinishEventLoop(); +} + void __IoInit() { INFO_LOG(SCEIO, "Starting up I/O..."); @@ -458,6 +462,7 @@ void __IoInit() { ioManagerThreadEnabled = g_Config.bSeparateIOThread; ioManager.SetThreadEnabled(ioManagerThreadEnabled); if (ioManagerThreadEnabled) { + Core_ListenShutdown(&__IoWakeManager); ioManagerThread = new std::thread(&__IoManagerThread); } diff --git a/Core/System.cpp b/Core/System.cpp index 51cb2a8baa..1e84d483a2 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -124,7 +124,7 @@ bool CPU_HasPendingAction() { void CPU_WaitStatus(bool (*pred)()) { cpuThreadLock.lock(); while (!pred()) - cpuThreadCond.wait_for(cpuThreadLock, 16); + cpuThreadCond.wait(cpuThreadLock); cpuThreadLock.unlock(); } @@ -255,6 +255,12 @@ void Core_UpdateState(CoreState newState) { Core_UpdateSingleStep(); } +void System_Wake() { + if (gpu) { + gpu->FinishEventLoop(); + } +} + bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) { INFO_LOG(BOOT, "PPSSPP %s", PPSSPP_GIT_VERSION); @@ -262,6 +268,7 @@ bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) { coreParameter.errorString = ""; if (g_Config.bSeparateCPUThread) { + Core_ListenShutdown(System_Wake); CPU_SetState(CPU_THREAD_PENDING); cpuThread = new std::thread(&CPU_RunLoop); CPU_WaitStatus(&CPU_IsReady); @@ -286,9 +293,9 @@ bool PSP_IsInited() { } void PSP_Shutdown() { - Core_NotifyShutdown(); if (coreState == CORE_RUNNING) Core_UpdateState(CORE_ERROR); + Core_NotifyShutdown(); if (cpuThread != NULL) { CPU_SetState(CPU_THREAD_SHUTDOWN); CPU_WaitStatus(&CPU_IsShutdown); diff --git a/Core/ThreadEventQueue.h b/Core/ThreadEventQueue.h index 55fddbcc0e..54aa45cd52 100644 --- a/Core/ThreadEventQueue.h +++ b/Core/ThreadEventQueue.h @@ -81,7 +81,7 @@ struct ThreadEventQueue : public B { } // coreState changes won't wake us, so recheck periodically. - eventsWait_.wait_for(eventsWaitLock_, 1); + eventsWait_.wait(eventsWaitLock_); } while (CoreTiming::GetTicks() < globalticks); }