output/MultipleOutputs: parallelize EnableDisable()

This commit is contained in:
Max Kellermann 2016-12-14 08:41:22 +01:00
parent 6425b4f9f5
commit 7e1b53480e
3 changed files with 20 additions and 13 deletions

View File

@ -323,34 +323,34 @@ public:
void LockCommandWait(Command cmd); void LockCommandWait(Command cmd);
/** /**
* Enables the device. * Enables the device, but don't wait for completion.
* *
* Caller must lock the mutex. * Caller must lock the mutex.
*/ */
void EnableWait(); void EnableAsync();
/** /**
* Disables the device. * Disables the device, but don't wait for completion.
* *
* Caller must lock the mutex. * Caller must lock the mutex.
*/ */
void DisableWait(); void DisableAsync();
/** /**
* Attempt to enable or disable the device as specified by the * Attempt to enable or disable the device as specified by the
* #enabled attribute; attempt to sync it with #really_enabled * #enabled attribute; attempt to sync it with #really_enabled
* (wrapper for EnableWait() or DisableWait()). * (wrapper for EnableAsync() or DisableAsync()).
* *
* Caller must lock the mutex. * Caller must lock the mutex.
*/ */
void EnableDisableWait() { void EnableDisableAsync() {
if (enabled == really_enabled) if (enabled == really_enabled)
return; return;
if (enabled) if (enabled)
EnableWait(); EnableAsync();
else else
DisableWait(); DisableAsync();
} }
void LockPauseAsync(); void LockPauseAsync();

View File

@ -107,9 +107,16 @@ MultipleOutputs::FindByName(const char *name) const
void void
MultipleOutputs::EnableDisable() MultipleOutputs::EnableDisable()
{ {
/* parallel execution */
for (auto ao : outputs) { for (auto ao : outputs) {
const ScopeLock lock(ao->mutex); const ScopeLock lock(ao->mutex);
ao->EnableDisableWait(); ao->EnableDisableAsync();
}
for (auto ao : outputs) {
const ScopeLock lock(ao->mutex);
ao->WaitForCommand();
} }
} }

View File

@ -70,7 +70,7 @@ AudioOutput::LockCommandWait(Command cmd)
} }
void void
AudioOutput::EnableWait() AudioOutput::EnableAsync()
{ {
if (!thread.IsDefined()) { if (!thread.IsDefined()) {
if (plugin.enable == nullptr) { if (plugin.enable == nullptr) {
@ -84,11 +84,11 @@ AudioOutput::EnableWait()
StartThread(); StartThread();
} }
CommandWait(Command::ENABLE); CommandAsync(Command::ENABLE);
} }
void void
AudioOutput::DisableWait() AudioOutput::DisableAsync()
{ {
if (!thread.IsDefined()) { if (!thread.IsDefined()) {
if (plugin.disable == nullptr) if (plugin.disable == nullptr)
@ -101,7 +101,7 @@ AudioOutput::DisableWait()
return; return;
} }
CommandWait(Command::DISABLE); CommandAsync(Command::DISABLE);
} }
inline bool inline bool