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

This commit is contained in:
Max Kellermann 2017-12-22 09:35:31 +01:00
parent 27b0a581a6
commit 6439727afc

View File

@ -1157,7 +1157,7 @@ PlayerControl::RunThread() noexcept
MusicBuffer buffer(buffer_chunks); MusicBuffer buffer(buffer_chunks);
Lock(); const std::lock_guard<Mutex> lock(mutex);
while (1) { while (1) {
switch (command) { switch (command) {
@ -1165,16 +1165,19 @@ PlayerControl::RunThread() noexcept
case PlayerCommand::QUEUE: case PlayerCommand::QUEUE:
assert(next_song != nullptr); assert(next_song != nullptr);
Unlock(); {
do_play(*this, dc, buffer); const ScopeUnlock unlock(mutex);
listener.OnPlayerSync(); do_play(*this, dc, buffer);
Lock(); listener.OnPlayerSync();
}
break; break;
case PlayerCommand::STOP: case PlayerCommand::STOP:
Unlock(); {
outputs.Cancel(); const ScopeUnlock unlock(mutex);
Lock(); outputs.Cancel();
}
/* fall through */ /* fall through */
@ -1185,11 +1188,11 @@ PlayerControl::RunThread() noexcept
break; break;
case PlayerCommand::CLOSE_AUDIO: case PlayerCommand::CLOSE_AUDIO:
Unlock(); {
const ScopeUnlock unlock(mutex);
outputs.Release();
}
outputs.Release();
Lock();
CommandFinished(); CommandFinished();
assert(buffer.IsEmptyUnsafe()); assert(buffer.IsEmptyUnsafe());
@ -1197,20 +1200,22 @@ PlayerControl::RunThread() noexcept
break; break;
case PlayerCommand::UPDATE_AUDIO: case PlayerCommand::UPDATE_AUDIO:
Unlock(); {
outputs.EnableDisable(); const ScopeUnlock unlock(mutex);
Lock(); outputs.EnableDisable();
}
CommandFinished(); CommandFinished();
break; break;
case PlayerCommand::EXIT: case PlayerCommand::EXIT:
Unlock(); {
const ScopeUnlock unlock(mutex);
dc.Quit();
outputs.Close();
}
dc.Quit(); CommandFinished();
outputs.Close();
LockCommandFinished();
return; return;
case PlayerCommand::CANCEL: case PlayerCommand::CANCEL: