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()
{
Lock();
close = true;
wake_cond.signal();
Unlock();
{
const ScopeLock lock(mutex);
close = true;
wake_cond.signal();
}
Cancel();
@ -61,10 +62,10 @@ ThreadInputStream::ThreadFunc()
{
FormatThreadName("input:%s", plugin);
Lock();
const ScopeLock lock(mutex);
if (!Open(postponed_error)) {
cond.broadcast();
Unlock();
return;
}
@ -78,12 +79,14 @@ ThreadInputStream::ThreadFunc()
if (w.IsEmpty()) {
wake_cond.wait(mutex);
} else {
Unlock();
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();
if (nbytes == 0) {
@ -96,8 +99,6 @@ ThreadInputStream::ThreadFunc()
}
}
Unlock();
Close();
}