event/Call, ...: use wait() with predicate
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
@@ -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, {}));
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user