decoder/api: use class ScopeLock

This commit is contained in:
Max Kellermann
2016-05-02 23:33:08 +02:00
parent eca6b9f0af
commit 280d35a053

View File

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