mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-25 02:38:42 +00:00
Don't busy wait in the audio thread (ALSA)
When the emulation is paused and the ALSA backend is used, make the audio thread wait on a condition variable instead of busy-waiting. This commit fixes bug #7729 Since the ALSA API is not thread-safe, calls to snd_pcm_drop() and snd_pcm_prepare() in AlsaSound::Clear() are protected by the same mutex as the condition variable in AlsaSound::SoundLoop() to make sure that we do not call these functions while a call to snd_pcm_writei() is ongoing.
This commit is contained in:
parent
a0c5247743
commit
333f998123
2 changed files with 33 additions and 1 deletions
|
@ -5,6 +5,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#if defined(HAVE_ALSA) && HAVE_ALSA
|
||||
|
@ -25,6 +27,7 @@ public:
|
|||
void SoundLoop() override;
|
||||
void Stop() override;
|
||||
void Update() override;
|
||||
void Clear(bool) override;
|
||||
|
||||
static bool isValid()
|
||||
{
|
||||
|
@ -45,6 +48,8 @@ private:
|
|||
u8 *mix_buffer;
|
||||
std::thread thread;
|
||||
std::atomic<ALSAThreadStatus> m_thread_status;
|
||||
std::condition_variable cv;
|
||||
std::mutex cv_m;
|
||||
|
||||
snd_pcm_t *handle;
|
||||
int frames_to_deliver;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue