Commit 973c87b3 authored by Max Kellermann's avatar Max Kellermann

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

parent 72fc1173
...@@ -53,8 +53,7 @@ public: ...@@ -53,8 +53,7 @@ public:
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock<Mutex> lock(mutex);
while (!done) cond.wait(lock, [this]{ return done; });
cond.wait(lock);
} }
if (exception) if (exception)
......
...@@ -136,8 +136,8 @@ AsyncInputStream::Seek(std::unique_lock<Mutex> &lock, ...@@ -136,8 +136,8 @@ AsyncInputStream::Seek(std::unique_lock<Mutex> &lock,
CondInputStreamHandler cond_handler; CondInputStreamHandler cond_handler;
const ScopeExchangeInputStreamHandler h(*this, &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(); Check();
} }
......
...@@ -84,8 +84,7 @@ BufferedInputStream::Seek(std::unique_lock<Mutex> &lock, ...@@ -84,8 +84,7 @@ BufferedInputStream::Seek(std::unique_lock<Mutex> &lock,
seek = true; seek = true;
wake_cond.notify_one(); wake_cond.notify_one();
while (seek) client_cond.wait(lock, [this]{ return !seek; });
client_cond.wait(lock);
if (seek_error) if (seek_error)
std::rethrow_exception(std::exchange(seek_error, {})); std::rethrow_exception(std::exchange(seek_error, {}));
......
...@@ -59,13 +59,10 @@ InputStream::OpenReady(const char *uri, Mutex &mutex) ...@@ -59,13 +59,10 @@ InputStream::OpenReady(const char *uri, Mutex &mutex)
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock<Mutex> lock(mutex);
while (true) { handler.cond.wait(lock, [&is]{
is->Update(); is->Update();
if (is->IsReady()) return is->IsReady();
break; });
handler.cond.wait(lock);
}
is->Check(); is->Check();
} }
......
...@@ -92,8 +92,7 @@ void ...@@ -92,8 +92,7 @@ void
ProxyInputStream::Seek(std::unique_lock<Mutex> &lock, ProxyInputStream::Seek(std::unique_lock<Mutex> &lock,
offset_type new_offset) offset_type new_offset)
{ {
while (!input) set_input_cond.wait(lock, [this]{ return !!input; });
set_input_cond.wait(lock);
input->Seek(lock, new_offset); input->Seek(lock, new_offset);
CopyAttributes(); CopyAttributes();
...@@ -124,8 +123,7 @@ size_t ...@@ -124,8 +123,7 @@ size_t
ProxyInputStream::Read(std::unique_lock<Mutex> &lock, ProxyInputStream::Read(std::unique_lock<Mutex> &lock,
void *ptr, size_t read_size) void *ptr, size_t read_size)
{ {
while (!input) set_input_cond.wait(lock, [this]{ return !!input; });
set_input_cond.wait(lock);
size_t nbytes = input->Read(lock, ptr, read_size); size_t nbytes = input->Read(lock, ptr, read_size);
CopyAttributes(); CopyAttributes();
......
...@@ -114,8 +114,7 @@ AudioOutputControl::LockToggleEnabled() noexcept ...@@ -114,8 +114,7 @@ AudioOutputControl::LockToggleEnabled() noexcept
void void
AudioOutputControl::WaitForCommand(std::unique_lock<Mutex> &lock) noexcept AudioOutputControl::WaitForCommand(std::unique_lock<Mutex> &lock) noexcept
{ {
while (!IsCommandFinished()) client_cond.wait(lock, [this]{ return IsCommandFinished(); });
client_cond.wait(lock);
} }
void void
......
...@@ -805,8 +805,7 @@ AlsaOutput::Drain() ...@@ -805,8 +805,7 @@ AlsaOutput::Drain()
Activate(); Activate();
while (drain && active) cond.wait(lock, [this]{ return !drain || !active; });
cond.wait(lock);
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);
......
...@@ -278,8 +278,7 @@ HttpdOutput::BroadcastFromEncoder() ...@@ -278,8 +278,7 @@ HttpdOutput::BroadcastFromEncoder()
/* synchronize with the IOThread */ /* synchronize with the IOThread */
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock<Mutex> lock(mutex);
while (!pages.empty()) cond.wait(lock, [this]{ return pages.empty(); });
cond.wait(lock);
} }
bool empty = true; bool empty = true;
......
...@@ -321,10 +321,10 @@ SlesOutput::Play(const void *chunk, size_t size) ...@@ -321,10 +321,10 @@ SlesOutput::Play(const void *chunk, size_t size)
assert(filled < BUFFER_SIZE); assert(filled < BUFFER_SIZE);
while (n_queued == N_BUFFERS) { cond.wait(lock, [this]{
assert(filled == 0); assert(filled == 0);
cond.wait(lock); return n_queued != N_BUFFERS;
} });
size_t nbytes = std::min(BUFFER_SIZE - filled, size); size_t nbytes = std::min(BUFFER_SIZE - filled, size);
memcpy(buffers[next] + filled, chunk, nbytes); memcpy(buffers[next] + filled, chunk, nbytes);
...@@ -350,8 +350,7 @@ SlesOutput::Drain() ...@@ -350,8 +350,7 @@ SlesOutput::Drain()
assert(filled < BUFFER_SIZE); assert(filled < BUFFER_SIZE);
while (n_queued > 0) cond.wait(lock, [this]{ return n_queued == 0; });
cond.wait(lock);
} }
void void
......
...@@ -125,8 +125,7 @@ public: ...@@ -125,8 +125,7 @@ public:
void Wait() { void Wait() {
std::unique_lock<Mutex> lock(mutex); std::unique_lock<Mutex> lock(mutex);
while (!done) cond.wait(lock, [this]{ return done; });
cond.wait(lock);
if (postponed_error) if (postponed_error)
std::rethrow_exception(postponed_error); std::rethrow_exception(postponed_error);
......
...@@ -209,8 +209,7 @@ UdisksStorage::MountWait() ...@@ -209,8 +209,7 @@ UdisksStorage::MountWait()
defer_mount.Schedule(); defer_mount.Schedule();
} }
while (want_mount) cond.wait(lock, [this]{ return !want_mount; });
cond.wait(lock);
if (mount_error) if (mount_error)
std::rethrow_exception(mount_error); std::rethrow_exception(mount_error);
...@@ -280,8 +279,7 @@ UdisksStorage::UnmountWait() ...@@ -280,8 +279,7 @@ UdisksStorage::UnmountWait()
defer_unmount.Schedule(); defer_unmount.Schedule();
while (mounted_storage) cond.wait(lock, [this]{ return !mounted_storage; });
cond.wait(lock);
if (mount_error) if (mount_error)
std::rethrow_exception(mount_error); std::rethrow_exception(mount_error);
......
...@@ -176,8 +176,7 @@ class DumpRemoteTagHandler final : public RemoteTagHandler { ...@@ -176,8 +176,7 @@ class DumpRemoteTagHandler final : public RemoteTagHandler {
public: public:
Tag Wait() { Tag Wait() {
std::unique_lock<Mutex> lock(mutex); std::unique_lock<Mutex> lock(mutex);
while (!done) cond.wait(lock, [this]{ return done; });
cond.wait(lock);
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment