From dca22e08eb96a401406ef7fa62c59eea1b837f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 5 Aug 2016 16:04:39 +0200 Subject: Use Common::Flag and Common::Event when possible Replaces old and simple usages of std::atomic with Common::Flag (which was introduced after the initial usage), so it's clear that the variable is a flag and because Common::Flag is well tested. This also replaces the ready logic in WiimoteReal with Common::Event since it was basically just unnecessarily reimplementing Common::Event. --- Source/Core/AudioCommon/AOSoundStream.cpp | 6 +++--- Source/Core/AudioCommon/AOSoundStream.h | 3 +-- Source/Core/AudioCommon/OpenALStream.cpp | 6 +++--- Source/Core/AudioCommon/OpenALStream.h | 3 +-- Source/Core/AudioCommon/PulseAudioStream.cpp | 6 +++--- Source/Core/AudioCommon/PulseAudioStream.h | 5 ++--- 6 files changed, 13 insertions(+), 16 deletions(-) (limited to 'Source/Core/AudioCommon') diff --git a/Source/Core/AudioCommon/AOSoundStream.cpp b/Source/Core/AudioCommon/AOSoundStream.cpp index 6dc1219e88..93f1759785 100644 --- a/Source/Core/AudioCommon/AOSoundStream.cpp +++ b/Source/Core/AudioCommon/AOSoundStream.cpp @@ -34,7 +34,7 @@ void AOSound::SoundLoop() buf_size = format.bits / 8 * format.channels * format.rate; - while (m_run_thread.load()) + while (m_run_thread.IsSet()) { m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2); @@ -49,7 +49,7 @@ void AOSound::SoundLoop() bool AOSound::Start() { - m_run_thread.store(true); + m_run_thread.Set(); memset(realtimeBuffer, 0, sizeof(realtimeBuffer)); thread = std::thread(&AOSound::SoundLoop, this); @@ -63,7 +63,7 @@ void AOSound::Update() void AOSound::Stop() { - m_run_thread.store(false); + m_run_thread.Clear(); soundSyncEvent.Set(); { diff --git a/Source/Core/AudioCommon/AOSoundStream.h b/Source/Core/AudioCommon/AOSoundStream.h index a62aafd35f..f81bca64da 100644 --- a/Source/Core/AudioCommon/AOSoundStream.h +++ b/Source/Core/AudioCommon/AOSoundStream.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include @@ -20,7 +19,7 @@ class AOSound final : public SoundStream { #if defined(HAVE_AO) && HAVE_AO std::thread thread; - std::atomic m_run_thread; + Common::Flag m_run_thread; std::mutex soundCriticalSection; Common::Event soundSyncEvent; diff --git a/Source/Core/AudioCommon/OpenALStream.cpp b/Source/Core/AudioCommon/OpenALStream.cpp index 9f0ea2af57..38dc90cd4d 100644 --- a/Source/Core/AudioCommon/OpenALStream.cpp +++ b/Source/Core/AudioCommon/OpenALStream.cpp @@ -25,7 +25,7 @@ static soundtouch::SoundTouch soundTouch; // bool OpenALStream::Start() { - m_run_thread.store(true); + m_run_thread.Set(); bool bReturn = false; ALDeviceList pDeviceList; @@ -75,7 +75,7 @@ bool OpenALStream::Start() void OpenALStream::Stop() { - m_run_thread.store(false); + m_run_thread.Clear(); // kick the thread if it's waiting soundSyncEvent.Set(); @@ -207,7 +207,7 @@ void OpenALStream::SoundLoop() soundTouch.setSetting(SETTING_SEEKWINDOW_MS, 28); soundTouch.setSetting(SETTING_OVERLAP_MS, 12); - while (m_run_thread.load()) + while (m_run_thread.IsSet()) { // num_samples_to_render in this update - depends on SystemTimers::AUDIO_DMA_PERIOD. const u32 stereo_16_bit_size = 4; diff --git a/Source/Core/AudioCommon/OpenALStream.h b/Source/Core/AudioCommon/OpenALStream.h index 5528a7cdf5..4125dcf1ae 100644 --- a/Source/Core/AudioCommon/OpenALStream.h +++ b/Source/Core/AudioCommon/OpenALStream.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include "AudioCommon/SoundStream.h" @@ -68,7 +67,7 @@ public: static bool isValid() { return true; } private: std::thread thread; - std::atomic m_run_thread; + Common::Flag m_run_thread; Common::Event soundSyncEvent; diff --git a/Source/Core/AudioCommon/PulseAudioStream.cpp b/Source/Core/AudioCommon/PulseAudioStream.cpp index 7ada6478bd..e6e6a45ce2 100644 --- a/Source/Core/AudioCommon/PulseAudioStream.cpp +++ b/Source/Core/AudioCommon/PulseAudioStream.cpp @@ -27,7 +27,7 @@ bool PulseAudio::Start() NOTICE_LOG(AUDIO, "PulseAudio backend using %d channels", m_channels); - m_run_thread = true; + m_run_thread.Set(); m_thread = std::thread(&PulseAudio::SoundLoop, this); // Initialize DPL2 parameters @@ -38,7 +38,7 @@ bool PulseAudio::Start() void PulseAudio::Stop() { - m_run_thread = false; + m_run_thread.Clear(); m_thread.join(); } @@ -54,7 +54,7 @@ void PulseAudio::SoundLoop() if (PulseInit()) { - while (m_run_thread.load() && m_pa_connected == 1 && m_pa_error >= 0) + while (m_run_thread.IsSet() && m_pa_connected == 1 && m_pa_error >= 0) m_pa_error = pa_mainloop_iterate(m_pa_ml, 1, nullptr); if (m_pa_error < 0) diff --git a/Source/Core/AudioCommon/PulseAudioStream.h b/Source/Core/AudioCommon/PulseAudioStream.h index b2c1a58414..5821007664 100644 --- a/Source/Core/AudioCommon/PulseAudioStream.h +++ b/Source/Core/AudioCommon/PulseAudioStream.h @@ -8,10 +8,9 @@ #include #endif -#include - #include "AudioCommon/SoundStream.h" #include "Common/CommonTypes.h" +#include "Common/Flag.h" #include "Common/Thread.h" class PulseAudio final : public SoundStream @@ -41,7 +40,7 @@ private: static void UnderflowCallback(pa_stream* s, void* userdata); std::thread m_thread; - std::atomic m_run_thread; + Common::Flag m_run_thread; bool m_stereo; // stereo, else surround int m_bytespersample; -- cgit v1.2.3