AlsaSoundStream: Convert volatile variables to atomics
This commit is contained in:
parent
7b376abd3b
commit
353205132c
|
@ -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<short *>(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()
|
||||
|
|
|
@ -4,13 +4,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#if defined(HAVE_ALSA) && HAVE_ALSA
|
||||
#include <alsa/asoundlib.h>
|
||||
#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<int> thread_data;
|
||||
|
||||
snd_pcm_t *handle;
|
||||
int frames_to_deliver;
|
||||
|
|
Loading…
Reference in New Issue