event/Call, ...: use wait() with predicate
This commit is contained in:
parent
72fc117393
commit
973c87b351
|
@ -53,8 +53,7 @@ public:
|
|||
|
||||
{
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
while (!done)
|
||||
cond.wait(lock);
|
||||
cond.wait(lock, [this]{ return done; });
|
||||
}
|
||||
|
||||
if (exception)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue