output/Control: add another Cond attribute, replacing audio_output_client_notify

This commit is contained in:
Max Kellermann 2018-06-23 19:11:48 +02:00
parent 1bca29f9e2
commit 1624a5eb8d
6 changed files with 13 additions and 33 deletions

View File

@ -22,7 +22,6 @@
#include "Filtered.hxx" #include "Filtered.hxx"
#include "Domain.hxx" #include "Domain.hxx"
#include "mixer/MixerControl.hxx" #include "mixer/MixerControl.hxx"
#include "notify.hxx"
#include "filter/plugins/ReplayGainFilterPlugin.hxx" #include "filter/plugins/ReplayGainFilterPlugin.hxx"
#include "config/Block.hxx" #include "config/Block.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -35,8 +34,6 @@
automatically reopening the device */ automatically reopening the device */
static constexpr PeriodClock::Duration REOPEN_AFTER = std::chrono::seconds(10); static constexpr PeriodClock::Duration REOPEN_AFTER = std::chrono::seconds(10);
struct notify audio_output_client_notify;
AudioOutputControl::AudioOutputControl(std::unique_ptr<FilteredAudioOutput> _output, AudioOutputControl::AudioOutputControl(std::unique_ptr<FilteredAudioOutput> _output,
AudioOutputClient &_client) noexcept AudioOutputClient &_client) noexcept
:output(std::move(_output)), client(_client), :output(std::move(_output)), client(_client),
@ -116,10 +113,8 @@ AudioOutputControl::LockToggleEnabled() noexcept
void void
AudioOutputControl::WaitForCommand() noexcept AudioOutputControl::WaitForCommand() noexcept
{ {
while (!IsCommandFinished()) { while (!IsCommandFinished())
const ScopeUnlock unlock(mutex); client_cond.wait(mutex);
audio_output_client_notify.Wait();
}
} }
void void

View File

@ -93,6 +93,12 @@ class AudioOutputControl {
*/ */
Cond wake_cond; Cond wake_cond;
/**
* This condition object signals #command completion to the
* client.
*/
Cond client_cond;
/** /**
* Additional data for #command. Protected by #mutex. * Additional data for #command. Protected by #mutex.
*/ */

View File

@ -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. * Throws #std::runtime_error on error.
*/ */

View File

@ -26,7 +26,6 @@
#include "config/Block.hxx" #include "config/Block.hxx"
#include "config/ConfigGlobal.hxx" #include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx" #include "config/ConfigOption.hxx"
#include "notify.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include <stdexcept> #include <stdexcept>
@ -155,23 +154,14 @@ MultipleOutputs::EnableDisable()
} }
} }
bool void
MultipleOutputs::AllFinished() const noexcept MultipleOutputs::WaitAll() noexcept
{ {
for (auto *ao : outputs) { for (auto *ao : outputs) {
const std::lock_guard<Mutex> protect(ao->mutex); const std::lock_guard<Mutex> protect(ao->mutex);
if (ao->IsBusy()) if (ao->IsBusy())
return false; ao->WaitForCommand();
} }
return true;
}
void
MultipleOutputs::WaitAll() noexcept
{
while (!AllFinished())
audio_output_client_notify.Wait();
} }
void void

View File

@ -145,12 +145,9 @@ public:
private: private:
/** /**
* Determine if all (active) outputs have finished the current * Wait until all (active) outputs have finished the current
* command. * command.
*/ */
gcc_pure
bool AllFinished() const noexcept;
void WaitAll() noexcept; void WaitAll() noexcept;
/** /**

View File

@ -22,7 +22,6 @@
#include "Filtered.hxx" #include "Filtered.hxx"
#include "Client.hxx" #include "Client.hxx"
#include "Domain.hxx" #include "Domain.hxx"
#include "notify.hxx"
#include "mixer/MixerInternal.hxx" #include "mixer/MixerInternal.hxx"
#include "thread/Util.hxx" #include "thread/Util.hxx"
#include "thread/Slack.hxx" #include "thread/Slack.hxx"
@ -41,8 +40,7 @@ AudioOutputControl::CommandFinished() noexcept
assert(command != Command::NONE); assert(command != Command::NONE);
command = Command::NONE; command = Command::NONE;
const ScopeUnlock unlock(mutex); client_cond.signal();
audio_output_client_notify.Signal();
} }
inline void inline void