From db80ff5477ed71286d2945b507adccf2030638b5 Mon Sep 17 00:00:00 2001 From: Gauvain 'GovanifY' Roussel-Tarbouriech Date: Sat, 19 Jun 2021 09:46:34 +0200 Subject: [PATCH] mtgs: fix threading woes --- pcsx2/MTGS.cpp | 10 +++++----- pcsx2/gui/GlobalCommands.cpp | 2 ++ pcsx2/gui/SysState.cpp | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index ece921aaa6..992c1fd5a7 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -595,14 +595,13 @@ void SysMtgsThread::CloseGS() if (!m_Opened || GSDump::isRunning) return; m_Opened = false; - Suspend(); + GSclose(); sApp.CloseGsPanel(); } void SysMtgsThread::OnSuspendInThread() { - GSclose(); - GetSysExecutorThread().PostEvent(new SysExecEvent_InvokeMtgsThreadMethod(&SysMtgsThread::CloseGS)); + CloseGS(); _parent::OnSuspendInThread(); } @@ -616,7 +615,7 @@ void SysMtgsThread::OnResumeInThread(bool isSuspended) void SysMtgsThread::OnCleanupInThread() { - GetSysExecutorThread().PostEvent(new SysExecEvent_InvokeMtgsThreadMethod(&SysMtgsThread::CloseGS)); + CloseGS(); _parent::OnCleanupInThread(); } @@ -925,8 +924,9 @@ void SysMtgsThread::WaitForOpen() void SysMtgsThread::Freeze(int mode, MTGS_FreezeData& data) { - Resume(); + pxAssertDev(!IsSelf(), "This method is only allowed from threads *not* named MTGS."); SendPointerPacket(GS_RINGTYPE_FREEZE, mode, &data); + // make sure MTGS is processing the packet we send it Resume(); // we are forced to wait for the semaphore to be released, otherwise // we'll end up in a state where the main thread is stuck on WaitGS diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index e23dbac952..fdff630a13 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -400,6 +400,7 @@ namespace Implementations return; if (renderswitch_delay == 0) { + ScopedCoreThreadPause paused_core; freezeData fP = {0, nullptr}; MTGS_FreezeData sstate = {&fP, 0}; GetMTGS().Freeze(FREEZE_SIZE, sstate); @@ -410,6 +411,7 @@ namespace Implementations GetMTGS().Freeze(FREEZE_LOAD, sstate); delete[] fP.data; renderswitch_delay = -1; + paused_core.AllowResume(); } } diff --git a/pcsx2/gui/SysState.cpp b/pcsx2/gui/SysState.cpp index 6a86d0932f..debaebbf40 100644 --- a/pcsx2/gui/SysState.cpp +++ b/pcsx2/gui/SysState.cpp @@ -53,8 +53,10 @@ struct SysState_Component int SysState_MTGSFreeze(int mode, freezeData* fP) { + ScopedCoreThreadPause paused_core; MTGS_FreezeData sstate = {fP, 0}; GetMTGS().Freeze(mode, sstate); + paused_core.AllowResume(); return sstate.retval; }