From 2939fadd6af89e56845892bf2c3d3506a4b950e4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 31 Dec 2015 13:45:10 +0100 Subject: [PATCH] decoder/Control: use ScopeLock --- src/decoder/DecoderControl.cxx | 4 +--- src/decoder/DecoderControl.hxx | 36 ++++++++++++---------------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/decoder/DecoderControl.cxx b/src/decoder/DecoderControl.cxx index fc3ab7ad8..6e2cf4a82 100644 --- a/src/decoder/DecoderControl.cxx +++ b/src/decoder/DecoderControl.cxx @@ -90,7 +90,7 @@ DecoderControl::Start(DetachedSong *_song, void DecoderControl::Stop() { - Lock(); + const ScopeLock protect(mutex); if (command != DecoderCommand::NONE) /* Attempt to cancel the current command. If it's too @@ -101,8 +101,6 @@ DecoderControl::Stop() if (state != DecoderState::STOP && state != DecoderState::ERROR) SynchronousCommandLocked(DecoderCommand::STOP); - - Unlock(); } bool diff --git a/src/decoder/DecoderControl.hxx b/src/decoder/DecoderControl.hxx index 35bd6828e..63cdb52a9 100644 --- a/src/decoder/DecoderControl.hxx +++ b/src/decoder/DecoderControl.hxx @@ -213,10 +213,8 @@ struct DecoderControl { gcc_pure bool LockIsIdle() const { - Lock(); - bool result = IsIdle(); - Unlock(); - return result; + const ScopeLock protect(mutex); + return IsIdle(); } bool IsStarting() const { @@ -225,10 +223,8 @@ struct DecoderControl { gcc_pure bool LockIsStarting() const { - Lock(); - bool result = IsStarting(); - Unlock(); - return result; + const ScopeLock protect(mutex); + return IsStarting(); } bool HasFailed() const { @@ -239,10 +235,8 @@ struct DecoderControl { gcc_pure bool LockHasFailed() const { - Lock(); - bool result = HasFailed(); - Unlock(); - return result; + const ScopeLock protect(mutex); + return HasFailed(); } /** @@ -267,10 +261,8 @@ struct DecoderControl { */ gcc_pure Error LockGetError() const { - Lock(); - Error result = GetError(); - Unlock(); - return result; + const ScopeLock protect(mutex); + return GetError(); } /** @@ -297,10 +289,8 @@ struct DecoderControl { gcc_pure bool LockIsCurrentSong(const DetachedSong &_song) const { - Lock(); - const bool result = IsCurrentSong(_song); - Unlock(); - return result; + const ScopeLock protect(mutex); + return IsCurrentSong(_song); } private: @@ -336,17 +326,15 @@ private: * object. */ void LockSynchronousCommand(DecoderCommand cmd) { - Lock(); + const ScopeLock protect(mutex); ClearError(); SynchronousCommandLocked(cmd); - Unlock(); } void LockAsynchronousCommand(DecoderCommand cmd) { - Lock(); + const ScopeLock protect(mutex); command = cmd; Signal(); - Unlock(); } public: