From b4cce80727221cf1740d5b78605d54776813c753 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 7 Aug 2017 16:34:29 +0200 Subject: [PATCH] output/Thread: move code to InternalClose() --- src/output/Control.hxx | 5 +++++ src/output/Thread.cxx | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/output/Control.hxx b/src/output/Control.hxx index 5802343db..215ca7c2e 100644 --- a/src/output/Control.hxx +++ b/src/output/Control.hxx @@ -422,6 +422,11 @@ private: void InternalOpen(AudioFormat audio_format, const MusicPipe &pipe) noexcept; + /** + * Runs inside the OutputThread. + */ + void InternalClose(bool drain) noexcept; + /** * Runs inside the OutputThread. */ diff --git a/src/output/Thread.cxx b/src/output/Thread.cxx index 3ab4df446..9a49ab6bd 100644 --- a/src/output/Thread.cxx +++ b/src/output/Thread.cxx @@ -172,16 +172,22 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format, } inline void -AudioOutputControl::InternalCheckClose(bool drain) noexcept +AudioOutputControl::InternalClose(bool drain) noexcept { - if (!IsOpen()) - return; + assert(IsOpen()); open = false; output->Close(drain); source.Close(); } +inline void +AudioOutputControl::InternalCheckClose(bool drain) noexcept +{ + if (IsOpen()) + InternalClose(drain); +} + /** * Wait until the output's delay reaches zero. * @@ -211,7 +217,7 @@ try { FormatError(e, "Failed to filter for output \"%s\" [%s]", GetName(), output->plugin.name); - InternalCheckClose(false); + InternalClose(false); /* don't automatically reopen this device for 10 seconds */ @@ -259,7 +265,7 @@ AudioOutputControl::PlayChunk() noexcept } if (nbytes == 0) { - InternalCheckClose(false); + InternalClose(false); /* don't automatically reopen this device for 10 seconds */ @@ -330,9 +336,7 @@ AudioOutputControl::InternalPause() noexcept break; if (!output->IteratePause()) { - open = false; - output->Close(false); - source.Close(); + InternalClose(false); break; } } while (command == Command::NONE);