1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +00:00

LibAudio: Restore exact audio enqueuer thread mutex behavior

This was changed with a recent move to MutexLocker, but the exact
previous behavior is safer as it holds the lock for the minimum amount
of time in both locations. We don't want to introduce these kinds of
subtle bugs.
This commit is contained in:
kleines Filmröllchen 2022-11-10 21:07:37 +01:00 committed by Andrew Kaster
parent 9d0b56b1fc
commit 3610b8dd93

View file

@ -27,8 +27,10 @@ ConnectionToServer::ConnectionToServer(NonnullOwnPtr<Core::Stream::LocalSocket>
Core::EventLoop enqueuer_loop;
m_enqueuer_loop = &enqueuer_loop;
enqueuer_loop.exec();
Threading::MutexLocker const locker(m_enqueuer_loop_destruction);
m_enqueuer_loop = nullptr;
{
Threading::MutexLocker const locker(m_enqueuer_loop_destruction);
m_enqueuer_loop = nullptr;
}
return (intptr_t) nullptr;
}))
{
@ -43,10 +45,13 @@ ConnectionToServer::~ConnectionToServer()
void ConnectionToServer::die()
{
// We're sometimes getting here after the other thread has already exited and its event loop does no longer exist.
if (Threading::MutexLocker const locker(m_enqueuer_loop_destruction); m_enqueuer_loop != nullptr) {
m_enqueuer_loop->wake();
m_enqueuer_loop->quit(0);
{
Threading::MutexLocker const locker(m_enqueuer_loop_destruction);
// We're sometimes getting here after the other thread has already exited and its event loop does no longer exist.
if (m_enqueuer_loop != nullptr) {
m_enqueuer_loop->wake();
m_enqueuer_loop->quit(0);
}
}
(void)m_background_audio_enqueuer->join();
}