output/MultipleOutputs: reduce lock/unlock calls in EnableDisable()

Use ScopeLock to manage the lock; don't unlock after obtaining the
"really_enabled" flag; keep the same lock during EnableWait() /
DisableWait().
This commit is contained in:
Max Kellermann 2016-12-14 07:54:05 +01:00
parent a9d7293818
commit ced3f320eb
3 changed files with 19 additions and 15 deletions

View File

@ -323,13 +323,17 @@ public:
/** /**
* Enables the device. * Enables the device.
*
* Caller must lock the mutex.
*/ */
void LockEnableWait(); void EnableWait();
/** /**
* Disables the device. * Disables the device.
*
* Caller must lock the mutex.
*/ */
void LockDisableWait(); void DisableWait();
void LockPauseAsync(); void LockPauseAsync();

View File

@ -44,7 +44,11 @@ MultipleOutputs::MultipleOutputs(MixerListener &_mixer_listener)
MultipleOutputs::~MultipleOutputs() MultipleOutputs::~MultipleOutputs()
{ {
for (auto i : outputs) { for (auto i : outputs) {
i->LockDisableWait(); {
const ScopeLock lock(i->mutex);
i->DisableWait();
}
i->Finish(); i->Finish();
} }
} }
@ -107,17 +111,13 @@ void
MultipleOutputs::EnableDisable() MultipleOutputs::EnableDisable()
{ {
for (auto ao : outputs) { for (auto ao : outputs) {
bool enabled; const ScopeLock lock(ao->mutex);
ao->mutex.lock(); if (ao->enabled != ao->really_enabled) {
enabled = ao->really_enabled;
ao->mutex.unlock();
if (ao->enabled != enabled) {
if (ao->enabled) if (ao->enabled)
ao->LockEnableWait(); ao->EnableWait();
else else
ao->LockDisableWait(); ao->DisableWait();
} }
} }
} }

View File

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