AudioCommon/WASAPI: Simplify thread synchronization model by not detaching WASAPI handler thread

This commit is contained in:
Silent 2019-08-17 10:08:16 +02:00
parent c5a372ab2a
commit ee60be4501
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
2 changed files with 3 additions and 16 deletions

View File

@ -45,12 +45,9 @@ WASAPIStream::WASAPIStream()
WASAPIStream::~WASAPIStream()
{
if (m_running)
{
m_running = false;
if (m_thread.joinable())
m_thread.join();
}
m_running = false;
if (m_thread.joinable())
m_thread.join();
}
bool WASAPIStream::isValid()
@ -332,7 +329,6 @@ bool WASAPIStream::SetRunning(bool running)
m_running = true;
m_thread = std::thread([this] { SoundLoop(); });
m_thread.detach();
}
else
{
@ -341,10 +337,6 @@ bool WASAPIStream::SetRunning(bool running)
if (m_thread.joinable())
m_thread.join();
while (!m_stopped)
{
}
m_need_data_event.reset();
m_audio_renderer.Reset();
m_audio_client.Reset();
@ -364,8 +356,6 @@ void WASAPIStream::SoundLoop()
m_audio_renderer->ReleaseBuffer(m_frames_in_buffer, AUDCLNT_BUFFERFLAGS_SILENT);
}
m_stopped = false;
while (m_running)
{
if (!m_audio_renderer)
@ -383,8 +373,6 @@ void WASAPIStream::SoundLoop()
m_audio_renderer->ReleaseBuffer(m_frames_in_buffer, 0);
}
m_stopped = true;
}
#endif // _WIN32

View File

@ -45,7 +45,6 @@ public:
private:
u32 m_frames_in_buffer = 0;
std::atomic<bool> m_running = false;
std::atomic<bool> m_stopped = false;
std::thread m_thread;
// CoUninitialize must be called after all WASAPI COM objects have been destroyed,