From e30ff7c327ff64d3a226476a0fd7165abc6e7937 Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 25 Aug 2019 18:00:43 +0200 Subject: [PATCH] DSPLLE: Put DSP thread in idle state if it's paused to prevent a deadlock DSP thread is considered "idle" when it signals s_ppc_event and waits for s_dsp_event, without putting it in this state when m_dsp_thread_mutex is locked it was possible to create a deadlock between a DSP thread, emulation thread and Qt thread by accessing Config menu immediately after booting up the game --- Source/Core/Core/HW/DSPLLE/DSPLLE.cpp | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp index 6f27f485fc..dc0f463fba 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp @@ -98,22 +98,24 @@ void DSPLLE::DSPThread(DSPLLE* dsp_lle) const int cycles = static_cast(dsp_lle->m_cycle_count.load()); if (cycles > 0) { - std::lock_guard dsp_thread_lock(dsp_lle->m_dsp_thread_mutex); - if (g_dsp_jit) + std::unique_lock dsp_thread_lock(dsp_lle->m_dsp_thread_mutex, std::try_to_lock); + if (dsp_thread_lock) { - DSPCore_RunCycles(cycles); + if (g_dsp_jit) + { + DSPCore_RunCycles(cycles); + } + else + { + DSP::Interpreter::RunCyclesThread(cycles); + } + dsp_lle->m_cycle_count.store(0); + continue; } - else - { - DSP::Interpreter::RunCyclesThread(cycles); - } - dsp_lle->m_cycle_count.store(0); - } - else - { - s_ppc_event.Set(); - s_dsp_event.Wait(); } + + s_ppc_event.Set(); + s_dsp_event.Wait(); } }