diff --git a/src/command/FingerprintCommands.cxx b/src/command/FingerprintCommands.cxx index ed957b899..933c80925 100644 --- a/src/command/FingerprintCommands.cxx +++ b/src/command/FingerprintCommands.cxx @@ -67,7 +67,7 @@ protected: void CancelThread() noexcept override { const std::lock_guard lock(mutex); cancel = true; - cond.signal(); + cond.notify_one(); } private: @@ -87,11 +87,11 @@ private: /* virtual methods from class InputStreamHandler */ void OnInputStreamReady() noexcept override { - cond.signal(); + cond.notify_one(); } void OnInputStreamAvailable() noexcept override { - cond.signal(); + cond.notify_one(); } }; diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx index 1a695cede..31daf531d 100644 --- a/src/decoder/Bridge.cxx +++ b/src/decoder/Bridge.cxx @@ -127,7 +127,7 @@ DecoderBridge::FlushChunk() noexcept const std::lock_guard protect(dc.mutex); if (dc.client_is_waiting) - dc.client_cond.signal(); + dc.client_cond.notify_one(); } bool @@ -310,7 +310,7 @@ DecoderBridge::CommandFinished() noexcept } dc.command = DecoderCommand::NONE; - dc.client_cond.signal(); + dc.client_cond.notify_one(); } SongTime diff --git a/src/decoder/Control.cxx b/src/decoder/Control.cxx index 5faa23fe5..8fc3334b2 100644 --- a/src/decoder/Control.cxx +++ b/src/decoder/Control.cxx @@ -67,7 +67,7 @@ DecoderControl::SetReady(const AudioFormat audio_format, total_time = _duration; state = DecoderState::DECODE; - client_cond.signal(); + client_cond.notify_one(); } bool diff --git a/src/decoder/Control.hxx b/src/decoder/Control.hxx index 899767751..91806b6a2 100644 --- a/src/decoder/Control.hxx +++ b/src/decoder/Control.hxx @@ -199,7 +199,7 @@ public: * calling this function. */ void Signal() noexcept { - cond.signal(); + cond.notify_one(); } /** @@ -367,7 +367,7 @@ public: assert(command != DecoderCommand::NONE); command = DecoderCommand::NONE; - client_cond.signal(); + client_cond.notify_one(); } /** @@ -428,11 +428,11 @@ private: /* virtual methods from class InputStreamHandler */ void OnInputStreamReady() noexcept override { - cond.signal(); + cond.notify_one(); } void OnInputStreamAvailable() noexcept override { - cond.signal(); + cond.notify_one(); } }; diff --git a/src/decoder/Thread.cxx b/src/decoder/Thread.cxx index 0dccbb4d2..cc2aa3d9d 100644 --- a/src/decoder/Thread.cxx +++ b/src/decoder/Thread.cxx @@ -450,7 +450,7 @@ decoder_run_song(DecoderControl &dc, throw FormatRuntimeError("Failed to decode %s", error_uri); } - dc.client_cond.signal(); + dc.client_cond.notify_one(); } /** @@ -479,7 +479,7 @@ try { dc.state = DecoderState::ERROR; dc.command = DecoderCommand::NONE; dc.error = std::current_exception(); - dc.client_cond.signal(); + dc.client_cond.notify_one(); } void diff --git a/src/event/Call.cxx b/src/event/Call.cxx index 6a04917ea..78d1e645d 100644 --- a/src/event/Call.cxx +++ b/src/event/Call.cxx @@ -73,7 +73,7 @@ private: const std::lock_guard lock(mutex); done = true; - cond.signal(); + cond.notify_one(); } }; diff --git a/src/input/BufferedInputStream.cxx b/src/input/BufferedInputStream.cxx index a5688de47..aebd790bb 100644 --- a/src/input/BufferedInputStream.cxx +++ b/src/input/BufferedInputStream.cxx @@ -50,7 +50,7 @@ BufferedInputStream::~BufferedInputStream() noexcept { const std::lock_guard lock(mutex); stop = true; - wake_cond.signal(); + wake_cond.notify_one(); } thread.Join(); @@ -81,7 +81,7 @@ BufferedInputStream::Seek(offset_type new_offset) seek_offset = new_offset; seek = true; - wake_cond.signal(); + wake_cond.notify_one(); while (seek) client_cond.wait(mutex); @@ -123,21 +123,21 @@ BufferedInputStream::Read(void *ptr, size_t s) if (!IsAvailable()) { /* wake up the sleeping thread */ idle = false; - wake_cond.signal(); + wake_cond.notify_one(); } return nbytes; } if (read_error) { - wake_cond.signal(); + wake_cond.notify_one(); std::rethrow_exception(std::exchange(read_error, {})); } if (idle) { /* wake up the sleeping thread */ idle = false; - wake_cond.signal(); + wake_cond.notify_one(); } client_cond.wait(mutex); @@ -163,7 +163,7 @@ BufferedInputStream::RunThread() noexcept idle = false; seek = false; - client_cond.signal(); + client_cond.notify_one(); } else if (!idle && !read_error && input->IsAvailable() && !input->IsEOF()) { const auto read_offset = input->GetOffset(); @@ -186,7 +186,7 @@ BufferedInputStream::RunThread() noexcept input->Seek(offset); } catch (...) { read_error = std::current_exception(); - client_cond.signal(); + client_cond.notify_one(); InvokeOnAvailable(); } } @@ -202,7 +202,7 @@ BufferedInputStream::RunThread() noexcept read_error = std::current_exception(); } - client_cond.signal(); + client_cond.notify_one(); InvokeOnAvailable(); } else wake_cond.wait(mutex); diff --git a/src/input/BufferedInputStream.hxx b/src/input/BufferedInputStream.hxx index a04c9e9ae..46a85a470 100644 --- a/src/input/BufferedInputStream.hxx +++ b/src/input/BufferedInputStream.hxx @@ -99,7 +99,7 @@ public: } void OnInputStreamAvailable() noexcept override { - wake_cond.signal(); + wake_cond.notify_one(); } private: diff --git a/src/input/CondHandler.hxx b/src/input/CondHandler.hxx index 3468ea68b..9172e5932 100644 --- a/src/input/CondHandler.hxx +++ b/src/input/CondHandler.hxx @@ -31,11 +31,11 @@ struct CondInputStreamHandler final : InputStreamHandler { /* virtual methods from class InputStreamHandler */ void OnInputStreamReady() noexcept override { - cond.signal(); + cond.notify_one(); } void OnInputStreamAvailable() noexcept override { - cond.signal(); + cond.notify_one(); } }; diff --git a/src/input/ProxyInputStream.cxx b/src/input/ProxyInputStream.cxx index 917e53fe1..f05f439f7 100644 --- a/src/input/ProxyInputStream.cxx +++ b/src/input/ProxyInputStream.cxx @@ -46,7 +46,7 @@ ProxyInputStream::SetInput(InputStreamPtr _input) noexcept ready */ CopyAttributes(); - set_input_cond.signal(); + set_input_cond.notify_one(); } void diff --git a/src/input/ThreadInputStream.cxx b/src/input/ThreadInputStream.cxx index aa38640c6..7a8e7f5d1 100644 --- a/src/input/ThreadInputStream.cxx +++ b/src/input/ThreadInputStream.cxx @@ -46,7 +46,7 @@ ThreadInputStream::Stop() noexcept { const std::lock_guard lock(mutex); close = true; - wake_cond.signal(); + wake_cond.notify_one(); } Cancel(); @@ -145,7 +145,7 @@ ThreadInputStream::Read(void *ptr, size_t read_size) size_t nbytes = std::min(read_size, r.size); memcpy(ptr, r.data, nbytes); buffer.Consume(nbytes); - wake_cond.broadcast(); + wake_cond.notify_all(); offset += nbytes; return nbytes; } diff --git a/src/lib/nfs/Blocking.hxx b/src/lib/nfs/Blocking.hxx index 5ec913c12..dc7ce5a4e 100644 --- a/src/lib/nfs/Blocking.hxx +++ b/src/lib/nfs/Blocking.hxx @@ -61,7 +61,7 @@ private: bool LockWaitFinished() noexcept { const std::lock_guard protect(mutex); while (!finished) - if (!cond.timed_wait(mutex, timeout)) + if (!cond.wait_for(mutex, timeout)) return false; return true; @@ -74,7 +74,7 @@ private: void LockSetFinished() noexcept { const std::lock_guard protect(mutex); finished = true; - cond.signal(); + cond.notify_one(); } /* virtual methods from NfsLease */ diff --git a/src/neighbor/plugins/SmbclientNeighborPlugin.cxx b/src/neighbor/plugins/SmbclientNeighborPlugin.cxx index 71e94266a..ec833372b 100644 --- a/src/neighbor/plugins/SmbclientNeighborPlugin.cxx +++ b/src/neighbor/plugins/SmbclientNeighborPlugin.cxx @@ -97,7 +97,7 @@ SmbclientNeighborExplorer::Close() noexcept { const std::lock_guard lock(mutex); quit = true; - cond.signal(); + cond.notify_one(); } thread.Join(); @@ -247,7 +247,7 @@ SmbclientNeighborExplorer::ThreadFunc() noexcept break; // TODO: sleep for how long? - cond.timed_wait(mutex, std::chrono::seconds(10)); + cond.wait_for(mutex, std::chrono::seconds(10)); } } diff --git a/src/output/Control.cxx b/src/output/Control.cxx index 45b1b6429..fdf31de90 100644 --- a/src/output/Control.cxx +++ b/src/output/Control.cxx @@ -122,7 +122,7 @@ AudioOutputControl::CommandAsync(Command cmd) noexcept assert(IsCommandFinished()); command = cmd; - wake_cond.signal(); + wake_cond.notify_one(); } void @@ -292,7 +292,7 @@ AudioOutputControl::LockPlay() noexcept if (IsOpen() && !in_playback_loop && !woken_for_play) { woken_for_play = true; - wake_cond.signal(); + wake_cond.notify_one(); } } @@ -340,7 +340,7 @@ AudioOutputControl::LockAllowPlay() noexcept allow_play = true; if (IsOpen()) - wake_cond.signal(); + wake_cond.notify_one(); } void diff --git a/src/output/Thread.cxx b/src/output/Thread.cxx index 847a6642e..f3a64e2d8 100644 --- a/src/output/Thread.cxx +++ b/src/output/Thread.cxx @@ -39,7 +39,7 @@ AudioOutputControl::CommandFinished() noexcept assert(command != Command::NONE); command = Command::NONE; - client_cond.signal(); + client_cond.notify_one(); } inline void @@ -215,7 +215,7 @@ AudioOutputControl::WaitForDelay() noexcept if (delay <= std::chrono::steady_clock::duration::zero()) return true; - (void)wake_cond.timed_wait(mutex, delay); + (void)wake_cond.wait_for(mutex, delay); if (command != Command::NONE) return false; diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index 8f32cf8d7..3f170e390 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -305,7 +305,7 @@ private: const std::lock_guard lock(mutex); /* notify the OutputThread that there is now room in ring_buffer */ - cond.signal(); + cond.notify_one(); return true; } @@ -330,7 +330,7 @@ private: const std::lock_guard lock(mutex); error = std::current_exception(); active = false; - cond.signal(); + cond.notify_one(); } /* virtual methods from class MultiSocketMonitor */ @@ -956,7 +956,7 @@ try { } drain = false; - cond.signal(); + cond.notify_one(); return; } } @@ -984,7 +984,7 @@ try { { const std::lock_guard lock(mutex); active = false; - cond.signal(); + cond.notify_one(); } /* avoid race condition: see if data has diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index 7a73ff999..c2230ce0e 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -120,7 +120,7 @@ HttpdOutput::OnDeferredBroadcast() noexcept /* wake up the client that may be waiting for the queue to be flushed */ - cond.broadcast(); + cond.notify_all(); } void @@ -398,7 +398,7 @@ HttpdOutput::CancelAllClients() noexcept for (auto &client : clients) client.CancelQueue(); - cond.broadcast(); + cond.notify_all(); } void diff --git a/src/output/plugins/sles/SlesOutputPlugin.cxx b/src/output/plugins/sles/SlesOutputPlugin.cxx index ced33b364..4971e5614 100644 --- a/src/output/plugins/sles/SlesOutputPlugin.cxx +++ b/src/output/plugins/sles/SlesOutputPlugin.cxx @@ -397,7 +397,7 @@ SlesOutput::PlayedCallback() const std::lock_guard protect(mutex); assert(n_queued > 0); --n_queued; - cond.signal(); + cond.notify_one(); } static bool diff --git a/src/player/Control.hxx b/src/player/Control.hxx index 542536067..c3f134549 100644 --- a/src/player/Control.hxx +++ b/src/player/Control.hxx @@ -351,7 +351,7 @@ private: * calling this function. */ void Signal() noexcept { - cond.signal(); + cond.notify_one(); } /** @@ -382,7 +382,7 @@ private: void ClientSignal() noexcept { assert(thread.IsInside()); - client_cond.signal(); + client_cond.notify_one(); } /** diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index b8ec0c78b..9c6e64e93 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -138,7 +138,7 @@ protected: request.Stop(); done = true; - cond.signal(); + cond.notify_one(); } void LockSetDone() { diff --git a/src/storage/plugins/NfsStorage.cxx b/src/storage/plugins/NfsStorage.cxx index 26854884d..b29f7be79 100644 --- a/src/storage/plugins/NfsStorage.cxx +++ b/src/storage/plugins/NfsStorage.cxx @@ -138,7 +138,7 @@ private: const std::lock_guard protect(mutex); state = _state; - cond.broadcast(); + cond.notify_all(); } void SetState(State _state, std::exception_ptr &&e) noexcept { @@ -147,7 +147,7 @@ private: const std::lock_guard protect(mutex); state = _state; last_exception = std::move(e); - cond.broadcast(); + cond.notify_all(); } void Connect() noexcept { diff --git a/src/storage/plugins/UdisksStorage.cxx b/src/storage/plugins/UdisksStorage.cxx index 1bd17b4e2..49c061d73 100644 --- a/src/storage/plugins/UdisksStorage.cxx +++ b/src/storage/plugins/UdisksStorage.cxx @@ -147,7 +147,7 @@ UdisksStorage::SetMountPoint(Path mount_point) mount_error = {}; want_mount = false; - cond.broadcast(); + cond.notify_all(); } void @@ -188,7 +188,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept const std::lock_guard lock(mutex); mount_error = std::current_exception(); want_mount = false; - cond.broadcast(); + cond.notify_all(); return; } @@ -247,7 +247,7 @@ try { const std::lock_guard lock(mutex); mount_error = std::current_exception(); want_mount = false; - cond.broadcast(); + cond.notify_all(); } void @@ -266,7 +266,7 @@ try { const std::lock_guard lock(mutex); mount_error = std::current_exception(); want_mount = false; - cond.broadcast(); + cond.notify_all(); } void @@ -306,7 +306,7 @@ try { const std::lock_guard lock(mutex); mount_error = std::current_exception(); mounted_storage.reset(); - cond.broadcast(); + cond.notify_all(); } void @@ -318,12 +318,12 @@ try { const std::lock_guard lock(mutex); mount_error = {}; mounted_storage.reset(); - cond.broadcast(); + cond.notify_all(); } catch (...) { const std::lock_guard lock(mutex); mount_error = std::current_exception(); mounted_storage.reset(); - cond.broadcast(); + cond.notify_all(); } std::string diff --git a/src/thread/PosixCond.hxx b/src/thread/PosixCond.hxx index ab00a654f..32079635b 100644 --- a/src/thread/PosixCond.hxx +++ b/src/thread/PosixCond.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2015 Max Kellermann + * Copyright 2009-2019 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -62,11 +62,11 @@ public: PosixCond(const PosixCond &other) = delete; PosixCond &operator=(const PosixCond &other) = delete; - void signal() noexcept { + void notify_one() noexcept { pthread_cond_signal(&cond); } - void broadcast() noexcept { + void notify_all() noexcept { pthread_cond_broadcast(&cond); } @@ -75,7 +75,7 @@ public: } private: - bool timed_wait(PosixMutex &mutex, uint_least32_t timeout_us) noexcept { + bool wait_for(PosixMutex &mutex, uint_least32_t timeout_us) noexcept { struct timeval now; gettimeofday(&now, nullptr); @@ -92,15 +92,15 @@ private: } public: - bool timed_wait(PosixMutex &mutex, - std::chrono::steady_clock::duration timeout) noexcept { + bool wait_for(PosixMutex &mutex, + std::chrono::steady_clock::duration timeout) noexcept { auto timeout_us = std::chrono::duration_cast(timeout).count(); if (timeout_us < 0) timeout_us = 0; else if (timeout_us > std::numeric_limits::max()) timeout_us = std::numeric_limits::max(); - return timed_wait(mutex, timeout_us); + return wait_for(mutex, timeout_us); } }; diff --git a/src/thread/WindowsCond.hxx b/src/thread/WindowsCond.hxx index 108f38c81..ef2777baf 100644 --- a/src/thread/WindowsCond.hxx +++ b/src/thread/WindowsCond.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 Max Kellermann + * Copyright 2009-2019 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,29 +48,29 @@ public: WindowsCond(const WindowsCond &other) = delete; WindowsCond &operator=(const WindowsCond &other) = delete; - void signal() noexcept { + void notify_one() noexcept { WakeConditionVariable(&cond); } - void broadcast() noexcept { + void notify_all() noexcept { WakeAllConditionVariable(&cond); } private: - bool timed_wait(CriticalSection &mutex, DWORD timeout_ms) noexcept { + bool wait_for(CriticalSection &mutex, DWORD timeout_ms) noexcept { return SleepConditionVariableCS(&cond, &mutex.critical_section, timeout_ms); } public: - bool timed_wait(CriticalSection &mutex, - std::chrono::steady_clock::duration timeout) noexcept { + bool wait_for(CriticalSection &mutex, + std::chrono::steady_clock::duration timeout) noexcept { auto timeout_ms = std::chrono::duration_cast(timeout).count(); - return timed_wait(mutex, timeout_ms); + return wait_for(mutex, timeout_ms); } void wait(CriticalSection &mutex) noexcept { - timed_wait(mutex, INFINITE); + wait_for(mutex, INFINITE); } }; diff --git a/test/run_input.cxx b/test/run_input.cxx index e5deafda8..eb6acda49 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -190,14 +190,14 @@ public: const std::lock_guard lock(mutex); tag = std::move(_tag); done = true; - cond.broadcast(); + cond.notify_all(); } void OnRemoteTagError(std::exception_ptr e) noexcept override { const std::lock_guard lock(mutex); error = std::move(e); done = true; - cond.broadcast(); + cond.notify_all(); } };