input/thread: use class ScopeLock and ScopeUnlock

This commit is contained in:
Max Kellermann 2016-09-16 17:22:16 +02:00
parent 13259225c2
commit 3cd07d0b54

View File

@ -28,10 +28,11 @@
ThreadInputStream::~ThreadInputStream() ThreadInputStream::~ThreadInputStream()
{ {
Lock(); {
close = true; const ScopeLock lock(mutex);
wake_cond.signal(); close = true;
Unlock(); wake_cond.signal();
}
Cancel(); Cancel();
@ -61,10 +62,10 @@ ThreadInputStream::ThreadFunc()
{ {
FormatThreadName("input:%s", plugin); FormatThreadName("input:%s", plugin);
Lock(); const ScopeLock lock(mutex);
if (!Open(postponed_error)) { if (!Open(postponed_error)) {
cond.broadcast(); cond.broadcast();
Unlock();
return; return;
} }
@ -78,12 +79,14 @@ ThreadInputStream::ThreadFunc()
if (w.IsEmpty()) { if (w.IsEmpty()) {
wake_cond.wait(mutex); wake_cond.wait(mutex);
} else { } else {
Unlock();
Error error; Error error;
size_t nbytes = ThreadRead(w.data, w.size, error); size_t nbytes;
{
const ScopeUnlock unlock(mutex);
nbytes = ThreadRead(w.data, w.size, error);
}
Lock();
cond.broadcast(); cond.broadcast();
if (nbytes == 0) { if (nbytes == 0) {
@ -96,8 +99,6 @@ ThreadInputStream::ThreadFunc()
} }
} }
Unlock();
Close(); Close();
} }