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

@ -53,8 +53,7 @@ public:
{
std::unique_lock<Mutex> lock(mutex);
while (!done)
cond.wait(lock);
cond.wait(lock, [this]{ return done; });
}
if (exception)

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();

View File

@ -114,8 +114,7 @@ AudioOutputControl::LockToggleEnabled() noexcept
void
AudioOutputControl::WaitForCommand(std::unique_lock<Mutex> &lock) noexcept
{
while (!IsCommandFinished())
client_cond.wait(lock);
client_cond.wait(lock, [this]{ return IsCommandFinished(); });
}
void

View File

@ -805,8 +805,7 @@ AlsaOutput::Drain()
Activate();
while (drain && active)
cond.wait(lock);
cond.wait(lock, [this]{ return !drain || !active; });
if (error)
std::rethrow_exception(error);

View File

@ -278,8 +278,7 @@ HttpdOutput::BroadcastFromEncoder()
/* synchronize with the IOThread */
{
std::unique_lock<Mutex> lock(mutex);
while (!pages.empty())
cond.wait(lock);
cond.wait(lock, [this]{ return pages.empty(); });
}
bool empty = true;

View File

@ -321,10 +321,10 @@ SlesOutput::Play(const void *chunk, size_t size)
assert(filled < BUFFER_SIZE);
while (n_queued == N_BUFFERS) {
cond.wait(lock, [this]{
assert(filled == 0);
cond.wait(lock);
}
return n_queued != N_BUFFERS;
});
size_t nbytes = std::min(BUFFER_SIZE - filled, size);
memcpy(buffers[next] + filled, chunk, nbytes);
@ -350,8 +350,7 @@ SlesOutput::Drain()
assert(filled < BUFFER_SIZE);
while (n_queued > 0)
cond.wait(lock);
cond.wait(lock, [this]{ return n_queued == 0; });
}
void

View File

@ -125,8 +125,7 @@ public:
void Wait() {
std::unique_lock<Mutex> lock(mutex);
while (!done)
cond.wait(lock);
cond.wait(lock, [this]{ return done; });
if (postponed_error)
std::rethrow_exception(postponed_error);

View File

@ -209,8 +209,7 @@ UdisksStorage::MountWait()
defer_mount.Schedule();
}
while (want_mount)
cond.wait(lock);
cond.wait(lock, [this]{ return !want_mount; });
if (mount_error)
std::rethrow_exception(mount_error);
@ -280,8 +279,7 @@ UdisksStorage::UnmountWait()
defer_unmount.Schedule();
while (mounted_storage)
cond.wait(lock);
cond.wait(lock, [this]{ return !mounted_storage; });
if (mount_error)
std::rethrow_exception(mount_error);

View File

@ -176,8 +176,7 @@ class DumpRemoteTagHandler final : public RemoteTagHandler {
public:
Tag Wait() {
std::unique_lock<Mutex> lock(mutex);
while (!done)
cond.wait(lock);
cond.wait(lock, [this]{ return done; });
if (error)
std::rethrow_exception(error);