Commit 6439727a authored by Max Kellermann's avatar Max Kellermann

player/Thread: use std::lock_guard in RunThread()

parent 27b0a581
......@@ -1157,7 +1157,7 @@ PlayerControl::RunThread() noexcept
MusicBuffer buffer(buffer_chunks);
Lock();
const std::lock_guard<Mutex> lock(mutex);
while (1) {
switch (command) {
......@@ -1165,16 +1165,19 @@ PlayerControl::RunThread() noexcept
case PlayerCommand::QUEUE:
assert(next_song != nullptr);
Unlock();
do_play(*this, dc, buffer);
listener.OnPlayerSync();
Lock();
{
const ScopeUnlock unlock(mutex);
do_play(*this, dc, buffer);
listener.OnPlayerSync();
}
break;
case PlayerCommand::STOP:
Unlock();
outputs.Cancel();
Lock();
{
const ScopeUnlock unlock(mutex);
outputs.Cancel();
}
/* fall through */
......@@ -1185,11 +1188,11 @@ PlayerControl::RunThread() noexcept
break;
case PlayerCommand::CLOSE_AUDIO:
Unlock();
outputs.Release();
{
const ScopeUnlock unlock(mutex);
outputs.Release();
}
Lock();
CommandFinished();
assert(buffer.IsEmptyUnsafe());
......@@ -1197,20 +1200,22 @@ PlayerControl::RunThread() noexcept
break;
case PlayerCommand::UPDATE_AUDIO:
Unlock();
outputs.EnableDisable();
Lock();
{
const ScopeUnlock unlock(mutex);
outputs.EnableDisable();
}
CommandFinished();
break;
case PlayerCommand::EXIT:
Unlock();
dc.Quit();
outputs.Close();
{
const ScopeUnlock unlock(mutex);
dc.Quit();
outputs.Close();
}
LockCommandFinished();
CommandFinished();
return;
case PlayerCommand::CANCEL:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment