From 1624a5eb8deda2ed9453a0f0391a929042814c81 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 23 Jun 2018 19:11:48 +0200 Subject: [PATCH] output/Control: add another Cond attribute, replacing audio_output_client_notify --- src/output/Control.cxx | 9 ++------- src/output/Control.hxx | 6 ++++++ src/output/Filtered.hxx | 6 ------ src/output/MultipleOutputs.cxx | 16 +++------------- src/output/MultipleOutputs.hxx | 5 +---- src/output/Thread.cxx | 4 +--- 6 files changed, 13 insertions(+), 33 deletions(-) diff --git a/src/output/Control.cxx b/src/output/Control.cxx index 86235ed4d..1c63f110f 100644 --- a/src/output/Control.cxx +++ b/src/output/Control.cxx @@ -22,7 +22,6 @@ #include "Filtered.hxx" #include "Domain.hxx" #include "mixer/MixerControl.hxx" -#include "notify.hxx" #include "filter/plugins/ReplayGainFilterPlugin.hxx" #include "config/Block.hxx" #include "Log.hxx" @@ -35,8 +34,6 @@ automatically reopening the device */ static constexpr PeriodClock::Duration REOPEN_AFTER = std::chrono::seconds(10); -struct notify audio_output_client_notify; - AudioOutputControl::AudioOutputControl(std::unique_ptr _output, AudioOutputClient &_client) noexcept :output(std::move(_output)), client(_client), @@ -116,10 +113,8 @@ AudioOutputControl::LockToggleEnabled() noexcept void AudioOutputControl::WaitForCommand() noexcept { - while (!IsCommandFinished()) { - const ScopeUnlock unlock(mutex); - audio_output_client_notify.Wait(); - } + while (!IsCommandFinished()) + client_cond.wait(mutex); } void diff --git a/src/output/Control.hxx b/src/output/Control.hxx index caf9260ac..711f86382 100644 --- a/src/output/Control.hxx +++ b/src/output/Control.hxx @@ -93,6 +93,12 @@ class AudioOutputControl { */ Cond wake_cond; + /** + * This condition object signals #command completion to the + * client. + */ + Cond client_cond; + /** * Additional data for #command. Protected by #mutex. */ diff --git a/src/output/Filtered.hxx b/src/output/Filtered.hxx index 3d79c193b..ed9d51e71 100644 --- a/src/output/Filtered.hxx +++ b/src/output/Filtered.hxx @@ -228,12 +228,6 @@ public: } }; -/** - * Notify object used by the thread's client, i.e. we will send a - * notify signal to this object, expecting the caller to wait on it. - */ -extern struct notify audio_output_client_notify; - /** * Throws #std::runtime_error on error. */ diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index ab4756d5d..5e8a2acea 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -26,7 +26,6 @@ #include "config/Block.hxx" #include "config/ConfigGlobal.hxx" #include "config/ConfigOption.hxx" -#include "notify.hxx" #include "util/RuntimeError.hxx" #include @@ -155,23 +154,14 @@ MultipleOutputs::EnableDisable() } } -bool -MultipleOutputs::AllFinished() const noexcept +void +MultipleOutputs::WaitAll() noexcept { for (auto *ao : outputs) { const std::lock_guard protect(ao->mutex); if (ao->IsBusy()) - return false; + ao->WaitForCommand(); } - - return true; -} - -void -MultipleOutputs::WaitAll() noexcept -{ - while (!AllFinished()) - audio_output_client_notify.Wait(); } void diff --git a/src/output/MultipleOutputs.hxx b/src/output/MultipleOutputs.hxx index aeb8d1c81..a01c78cfe 100644 --- a/src/output/MultipleOutputs.hxx +++ b/src/output/MultipleOutputs.hxx @@ -145,12 +145,9 @@ public: private: /** - * Determine if all (active) outputs have finished the current + * Wait until all (active) outputs have finished the current * command. */ - gcc_pure - bool AllFinished() const noexcept; - void WaitAll() noexcept; /** diff --git a/src/output/Thread.cxx b/src/output/Thread.cxx index 0ea35aa39..58b5abcfc 100644 --- a/src/output/Thread.cxx +++ b/src/output/Thread.cxx @@ -22,7 +22,6 @@ #include "Filtered.hxx" #include "Client.hxx" #include "Domain.hxx" -#include "notify.hxx" #include "mixer/MixerInternal.hxx" #include "thread/Util.hxx" #include "thread/Slack.hxx" @@ -41,8 +40,7 @@ AudioOutputControl::CommandFinished() noexcept assert(command != Command::NONE); command = Command::NONE; - const ScopeUnlock unlock(mutex); - audio_output_client_notify.Signal(); + client_cond.signal(); } inline void