From e81b089612833b61c566b482640615e182949ac6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 22 Jun 2018 23:09:13 +0200 Subject: [PATCH] MusicPipe: automatically clear in destructor We can implement this now that we have a MusicBuffer reference. --- src/MusicPipe.hxx | 8 ++------ src/output/MultipleOutputs.cxx | 14 ++++---------- src/player/Thread.cxx | 9 ++------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/MusicPipe.hxx b/src/MusicPipe.hxx index b3e28a656..fd0471fd4 100644 --- a/src/MusicPipe.hxx +++ b/src/MusicPipe.hxx @@ -67,12 +67,8 @@ public: MusicPipe(const MusicPipe &) = delete; - /** - * Frees the object. It must be empty now. - */ - ~MusicPipe() { - assert(head == nullptr); - assert(tail_r == &head); + ~MusicPipe() noexcept { + Clear(); } MusicPipe &operator=(const MusicPipe &) = delete; diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index b5c3e0e0b..6e993ba3a 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -407,11 +407,8 @@ MultipleOutputs::Close() noexcept for (auto *ao : outputs) ao->LockCloseWait(); - if (pipe != nullptr) { - pipe->Clear(); - delete pipe; - pipe = nullptr; - } + delete pipe; + pipe = nullptr; input_audio_format.Clear(); @@ -424,11 +421,8 @@ MultipleOutputs::Release() noexcept for (auto *ao : outputs) ao->LockRelease(); - if (pipe != nullptr) { - pipe->Clear(); - delete pipe; - pipe = nullptr; - } + delete pipe; + pipe = nullptr; input_audio_format.Clear(); diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index e20b9b3a9..b359ec4b8 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -169,14 +169,9 @@ private: xfade_state = CrossFadeState::UNKNOWN; } - void ClearAndDeletePipe() noexcept { - pipe->Clear(); - delete pipe; - } - void ClearAndReplacePipe(MusicPipe *_pipe) noexcept { ResetCrossFade(); - ClearAndDeletePipe(); + delete pipe; pipe = _pipe; } @@ -1070,7 +1065,7 @@ Player::Run() noexcept CancelPendingSeek(); StopDecoder(); - ClearAndDeletePipe(); + delete pipe; cross_fade_tag.reset();