From 7c46497f0472f633cfea153c4c86d8c04cf04d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 11 May 2019 16:26:03 +0200 Subject: [PATCH] Fix a race condition when shutting down audio stream The main EmuThread (in Core) is responsible for both initialising the audio stream and shutting it down properly. When the core is shutting down (when state is State::PowerDown), it is possible that the CPU or CPU-GPU thread and the UI thread will both try to stop the audio stream at the same time, which is an issue because some audio backends such as cubeb are not thread-safe. This commit prevents the race from ever happening in the first place by removing the call to AudioCommon::SetSoundStreamRunning from CPU::RunAdjacentSystems, which is actually completely unnecessary when shutting down because Core::EmuThread is going to stop the stream and perform more cleanup anyway. Should fix https://bugs.dolphin-emu.org/issues/11722 --- Source/Core/Core/HW/CPU.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/HW/CPU.cpp b/Source/Core/Core/HW/CPU.cpp index 5e3ebfe145..a1b21ea7a2 100644 --- a/Source/Core/Core/HW/CPU.cpp +++ b/Source/Core/Core/HW/CPU.cpp @@ -147,7 +147,9 @@ static void RunAdjacentSystems(bool running) { // NOTE: We're assuming these will not try to call Break or EnableStepping. Fifo::EmulatorState(running); - AudioCommon::SetSoundStreamRunning(running); + // Core is responsible for shutting down the sound stream. + if (s_state != State::PowerDown) + AudioCommon::SetSoundStreamRunning(running); } void Stop()