mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
Initialize ALSA before starting the audio thread
This fixes a race condition: Before this commit, there was a race condition when starting a game: Core::EmuThread(), after having started (but not necessarily completed) the initialization of the audio thread, calls Core::SetState() which calls CCPU::EnableStepping(), which in turns calls AudioCommon::ClearAudioBuffer(). This means that SoundStream::Clear() can be called before AlsaSound::AlsaInit() has completed.
This commit is contained in:
@ -26,6 +26,12 @@ AlsaSound::~AlsaSound()
|
|||||||
bool AlsaSound::Start()
|
bool AlsaSound::Start()
|
||||||
{
|
{
|
||||||
m_thread_status.store(ALSAThreadStatus::RUNNING);
|
m_thread_status.store(ALSAThreadStatus::RUNNING);
|
||||||
|
if (!AlsaInit())
|
||||||
|
{
|
||||||
|
m_thread_status.store(ALSAThreadStatus::STOPPED);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
thread = std::thread(&AlsaSound::SoundLoop, this);
|
thread = std::thread(&AlsaSound::SoundLoop, this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -44,10 +50,6 @@ void AlsaSound::Update()
|
|||||||
// Called on audio thread.
|
// Called on audio thread.
|
||||||
void AlsaSound::SoundLoop()
|
void AlsaSound::SoundLoop()
|
||||||
{
|
{
|
||||||
if (!AlsaInit()) {
|
|
||||||
m_thread_status.store(ALSAThreadStatus::STOPPED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Common::SetCurrentThreadName("Audio thread - alsa");
|
Common::SetCurrentThreadName("Audio thread - alsa");
|
||||||
while (m_thread_status.load() == ALSAThreadStatus::RUNNING)
|
while (m_thread_status.load() == ALSAThreadStatus::RUNNING)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user