From 353205132c6fa5da8edbe1a4097cef2fad872794 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 10 May 2015 00:20:27 -0400 Subject: [PATCH] AlsaSoundStream: Convert volatile variables to atomics --- Source/Core/AudioCommon/AlsaSoundStream.cpp | 10 +++++----- Source/Core/AudioCommon/AlsaSoundStream.h | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Source/Core/AudioCommon/AlsaSoundStream.cpp b/Source/Core/AudioCommon/AlsaSoundStream.cpp index 5f76c60de7..099a3dee35 100644 --- a/Source/Core/AudioCommon/AlsaSoundStream.cpp +++ b/Source/Core/AudioCommon/AlsaSoundStream.cpp @@ -23,13 +23,13 @@ AlsaSound::~AlsaSound() bool AlsaSound::Start() { thread = std::thread(&AlsaSound::SoundLoop, this); - thread_data = 0; + thread_data.store(0); return true; } void AlsaSound::Stop() { - thread_data = 1; + thread_data.store(1); thread.join(); } @@ -42,11 +42,11 @@ void AlsaSound::Update() void AlsaSound::SoundLoop() { if (!AlsaInit()) { - thread_data = 2; + thread_data.store(2); return; } Common::SetCurrentThreadName("Audio thread - alsa"); - while (!thread_data) + while (thread_data.load() == 0) { m_mixer->Mix(reinterpret_cast(mix_buffer), frames_to_deliver); int rc = m_muted ? 1337 : snd_pcm_writei(handle, mix_buffer, frames_to_deliver); @@ -61,7 +61,7 @@ void AlsaSound::SoundLoop() } } AlsaShutdown(); - thread_data = 2; + thread_data.store(2); } bool AlsaSound::AlsaInit() diff --git a/Source/Core/AudioCommon/AlsaSoundStream.h b/Source/Core/AudioCommon/AlsaSoundStream.h index 65173351f8..63b61fba90 100644 --- a/Source/Core/AudioCommon/AlsaSoundStream.h +++ b/Source/Core/AudioCommon/AlsaSoundStream.h @@ -4,13 +4,15 @@ #pragma once +#include +#include + #if defined(HAVE_ALSA) && HAVE_ALSA #include #endif #include "AudioCommon/SoundStream.h" #include "Common/CommonTypes.h" -#include "Common/Thread.h" class AlsaSound final : public SoundStream { @@ -39,7 +41,7 @@ private: // 0 = continue // 1 = shutdown // 2 = done shutting down. - volatile int thread_data; + std::atomic thread_data; snd_pcm_t *handle; int frames_to_deliver;