From 280d35a053d22e3791bade1215802effb268f8c0 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@duempel.org>
Date: Mon, 2 May 2016 23:33:08 +0200
Subject: [PATCH] decoder/api: use class ScopeLock

---
 src/decoder/DecoderAPI.cxx | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/decoder/DecoderAPI.cxx b/src/decoder/DecoderAPI.cxx
index 88088db18..a8ea57bf1 100644
--- a/src/decoder/DecoderAPI.cxx
+++ b/src/decoder/DecoderAPI.cxx
@@ -270,18 +270,14 @@ decoder_open_uri(Decoder &decoder, const char *uri, Error &error)
 	if (!is)
 		return nullptr;
 
-	mutex.lock();
+	const ScopeLock lock(mutex);
 	while (true) {
 		is->Update();
-		if (is->IsReady()) {
-			mutex.unlock();
+		if (is->IsReady())
 			return is;
-		}
 
-		if (dc.command == DecoderCommand::STOP) {
-			mutex.unlock();
+		if (dc.command == DecoderCommand::STOP)
 			return nullptr;
-		}
 
 		cond.wait(mutex);
 	}
@@ -326,13 +322,11 @@ decoder_read(Decoder *decoder,
 	if (length == 0)
 		return 0;
 
-	is.Lock();
+	ScopeLock lock(is.mutex);
 
 	while (true) {
-		if (decoder_check_cancel_read(decoder)) {
-			is.Unlock();
+		if (decoder_check_cancel_read(decoder))
 			return 0;
-		}
 
 		if (is.IsAvailable())
 			break;
@@ -345,7 +339,7 @@ decoder_read(Decoder *decoder,
 	assert(nbytes == 0 || !error.IsDefined());
 	assert(nbytes > 0 || error.IsDefined() || is.IsEOF());
 
-	is.Unlock();
+	lock.Unlock();
 
 	if (gcc_unlikely(nbytes == 0 && error.IsDefined()))
 		LogError(error);