summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/AlsaSoundStream.cpp
diff options
context:
space:
mode:
authorshuffle2 <godisgovernment@gmail.com>2015-10-03 17:55:26 -0700
committershuffle2 <godisgovernment@gmail.com>2015-10-03 17:55:26 -0700
commit98780048718817bb5cb37648ffb28d3250b2f3d5 (patch)
tree5f3308487af83d3552d9637508064498bec7359c /Source/Core/AudioCommon/AlsaSoundStream.cpp
parent91d805fbec6955f292f3efa62a05563a916c9301 (diff)
parenta10a3ecbaccbbbdc31be5898cbc9a88ab2d8b872 (diff)
Merge pull request #3105 from phire/dont_block
ALSA: Don't block on Clear() call.
Diffstat (limited to 'Source/Core/AudioCommon/AlsaSoundStream.cpp')
-rw-r--r--Source/Core/AudioCommon/AlsaSoundStream.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/Source/Core/AudioCommon/AlsaSoundStream.cpp b/Source/Core/AudioCommon/AlsaSoundStream.cpp
index 10b05e8441..19a21acf66 100644
--- a/Source/Core/AudioCommon/AlsaSoundStream.cpp
+++ b/Source/Core/AudioCommon/AlsaSoundStream.cpp
@@ -48,21 +48,31 @@ void AlsaSound::Update()
void AlsaSound::SoundLoop()
{
Common::SetCurrentThreadName("Audio thread - alsa");
- while (m_thread_status.load() == ALSAThreadStatus::RUNNING)
+ while (m_thread_status.load() != ALSAThreadStatus::STOPPING)
{
- std::unique_lock<std::mutex> lock(cv_m);
- cv.wait(lock, [this]{return !m_muted || m_thread_status.load() != ALSAThreadStatus::RUNNING;});
-
- m_mixer->Mix(mix_buffer, frames_to_deliver);
- int rc = snd_pcm_writei(handle, mix_buffer, frames_to_deliver);
- if (rc == -EPIPE)
+ while (m_thread_status.load() == ALSAThreadStatus::RUNNING)
{
- // Underrun
- snd_pcm_prepare(handle);
+ m_mixer->Mix(mix_buffer, frames_to_deliver);
+ int rc = snd_pcm_writei(handle, mix_buffer, frames_to_deliver);
+ if (rc == -EPIPE)
+ {
+ // Underrun
+ snd_pcm_prepare(handle);
+ }
+ else if (rc < 0)
+ {
+ ERROR_LOG(AUDIO, "writei fail: %s", snd_strerror(rc));
+ }
}
- else if (rc < 0)
+ if (m_thread_status.load() == ALSAThreadStatus::PAUSED)
{
- ERROR_LOG(AUDIO, "writei fail: %s", snd_strerror(rc));
+ snd_pcm_drop(handle); // Stop sound output
+
+ // Block until thread status changes.
+ std::unique_lock<std::mutex> lock(cv_m);
+ cv.wait(lock, [this]{ return m_thread_status.load() != ALSAThreadStatus::PAUSED; });
+
+ snd_pcm_prepare(handle); // resume sound output
}
}
AlsaShutdown();
@@ -73,18 +83,8 @@ void AlsaSound::SoundLoop()
void AlsaSound::Clear(bool muted)
{
m_muted = muted;
- if (m_muted)
- {
- std::lock_guard<std::mutex> lock(cv_m);
- snd_pcm_drop(handle);
- }
- else
- {
- std::unique_lock<std::mutex> lock(cv_m);
- snd_pcm_prepare(handle);
- lock.unlock();
- cv.notify_one();
- }
+ m_thread_status.store(muted ? ALSAThreadStatus::PAUSED : ALSAThreadStatus::RUNNING);
+ cv.notify_one(); // Notify thread that status has changed
}
bool AlsaSound::AlsaInit()