event/Call, ...: use wait() with predicate

This commit is contained in:
Max Kellermann
2019-05-07 20:01:45 +02:00
parent 72fc117393
commit 973c87b351
12 changed files with 20 additions and 35 deletions

View File

@@ -136,8 +136,8 @@ AsyncInputStream::Seek(std::unique_lock<Mutex> &lock,
CondInputStreamHandler cond_handler;
const ScopeExchangeInputStreamHandler h(*this, &cond_handler);
while (seek_state != SeekState::NONE)
cond_handler.cond.wait(lock);
cond_handler.cond.wait(lock,
[this]{ return seek_state == SeekState::NONE; });
Check();
}

View File

@@ -84,8 +84,7 @@ BufferedInputStream::Seek(std::unique_lock<Mutex> &lock,
seek = true;
wake_cond.notify_one();
while (seek)
client_cond.wait(lock);
client_cond.wait(lock, [this]{ return !seek; });
if (seek_error)
std::rethrow_exception(std::exchange(seek_error, {}));

View File

@@ -59,13 +59,10 @@ InputStream::OpenReady(const char *uri, Mutex &mutex)
{
std::unique_lock<Mutex> lock(mutex);
while (true) {
handler.cond.wait(lock, [&is]{
is->Update();
if (is->IsReady())
break;
handler.cond.wait(lock);
}
return is->IsReady();
});
is->Check();
}

View File

@@ -92,8 +92,7 @@ void
ProxyInputStream::Seek(std::unique_lock<Mutex> &lock,
offset_type new_offset)
{
while (!input)
set_input_cond.wait(lock);
set_input_cond.wait(lock, [this]{ return !!input; });
input->Seek(lock, new_offset);
CopyAttributes();
@@ -124,8 +123,7 @@ size_t
ProxyInputStream::Read(std::unique_lock<Mutex> &lock,
void *ptr, size_t read_size)
{
while (!input)
set_input_cond.wait(lock);
set_input_cond.wait(lock, [this]{ return !!input; });
size_t nbytes = input->Read(lock, ptr, read_size);
CopyAttributes();