From d34a9afe049d9b800a4ce70158091427cdb958be Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 6 Apr 2019 17:39:25 -0500 Subject: Minor changes to usages of std::condition_variable. --- Source/Core/AudioCommon/AlsaSoundStream.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Source/Core/AudioCommon/AlsaSoundStream.cpp') diff --git a/Source/Core/AudioCommon/AlsaSoundStream.cpp b/Source/Core/AudioCommon/AlsaSoundStream.cpp index 3d20331abd..d249640d1b 100644 --- a/Source/Core/AudioCommon/AlsaSoundStream.cpp +++ b/Source/Core/AudioCommon/AlsaSoundStream.cpp @@ -19,6 +19,9 @@ AlsaSound::~AlsaSound() { m_thread_status.store(ALSAThreadStatus::STOPPING); + // Immediately lock and unlock mutex to prevent cv race. + std::unique_lock{cv_m}; + // Give the opportunity to the audio thread // to realize we are stopping the emulation cv.notify_one(); @@ -81,7 +84,12 @@ void AlsaSound::SoundLoop() bool AlsaSound::SetRunning(bool running) { m_thread_status.store(running ? ALSAThreadStatus::RUNNING : ALSAThreadStatus::PAUSED); - cv.notify_one(); // Notify thread that status has changed + + // Immediately lock and unlock mutex to prevent cv race. + std::unique_lock{cv_m}; + + // Notify thread that status has changed + cv.notify_one(); return true; } -- cgit v1.2.3