From 6425b4f9f56f5b98124cf7b006ede4ec8d86a567 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 14 Dec 2016 08:15:33 +0100 Subject: [PATCH] output/MultipleOutputs: parallelize AudioOutput destruction Reduce latency by stopping all AudioOutputs asynchronously. --- src/output/Internal.hxx | 3 ++- src/output/MultipleOutputs.cxx | 5 ++++- src/output/OutputControl.cxx | 13 +++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index a6f0d9d2e..6f45a44e7 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -283,7 +283,8 @@ public: void StartThread(); void StopThread(); - void Finish(); + void BeginDestroy(); + void FinishDestroy(); bool IsOpen() const { return open; diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index d5b6340d0..6f846faaa 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -43,8 +43,11 @@ MultipleOutputs::MultipleOutputs(MixerListener &_mixer_listener) MultipleOutputs::~MultipleOutputs() { + /* parallel destruction */ for (auto i : outputs) - i->Finish(); + i->BeginDestroy(); + for (auto i : outputs) + i->FinishDestroy(); } static AudioOutput * diff --git a/src/output/OutputControl.cxx b/src/output/OutputControl.cxx index e7221a171..01bca7ae8 100644 --- a/src/output/OutputControl.cxx +++ b/src/output/OutputControl.cxx @@ -274,13 +274,22 @@ AudioOutput::StopThread() } void -AudioOutput::Finish() +AudioOutput::BeginDestroy() { if (mixer != nullptr) mixer_auto_close(mixer); + if (thread.IsDefined()) { + const ScopeLock protect(mutex); + CommandAsync(Command::KILL); + } +} + +void +AudioOutput::FinishDestroy() +{ if (thread.IsDefined()) - StopThread(); + thread.Join(); audio_output_free(this); }