summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/AlsaSoundStream.cpp
diff options
context:
space:
mode:
authorConnor McLaughlin <stenzek@gmail.com>2019-04-21 23:50:53 +1000
committerGitHub <noreply@github.com>2019-04-21 23:50:53 +1000
commit44d5a71e2763964ded2a0594d3ad454b8a8e7615 (patch)
tree16f95e0dd1e7978c4b8e0d217add6003837a5a12 /Source/Core/AudioCommon/AlsaSoundStream.cpp
parentbb2fa2aba0bde2dc0ff279ce0f87a8efeebd7df4 (diff)
parentd34a9afe049d9b800a4ce70158091427cdb958be (diff)
Merge pull request #7965 from jordan-woyak/condvar-fixes
Minor changes to usages of std::condition_variable.
Diffstat (limited to 'Source/Core/AudioCommon/AlsaSoundStream.cpp')
-rw-r--r--Source/Core/AudioCommon/AlsaSoundStream.cpp10
1 files changed, 9 insertions, 1 deletions
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<std::mutex>{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<std::mutex>{cv_m};
+
+ // Notify thread that status has changed
+ cv.notify_one();
return true;
}