From 6439727afc515bc0244d8be020e6946dbf6bca10 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 22 Dec 2017 09:35:31 +0100 Subject: [PATCH] player/Thread: use std::lock_guard in RunThread() --- src/player/Thread.cxx | 47 ++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index f8d44821e..114d680f6 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -1157,7 +1157,7 @@ PlayerControl::RunThread() noexcept MusicBuffer buffer(buffer_chunks); - Lock(); + const std::lock_guard 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(); + { + const ScopeUnlock unlock(mutex); + outputs.Release(); + } - 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(); + { + const ScopeUnlock unlock(mutex); + dc.Quit(); + outputs.Close(); + } - dc.Quit(); - - outputs.Close(); - - LockCommandFinished(); + CommandFinished(); return; case PlayerCommand::CANCEL: