From 302c0515b7f86153ebd678e8d6f1342d38365620 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 May 2019 11:21:56 +0200 Subject: [PATCH] input/buffering: move code to RunThreadLocked() --- src/input/BufferingInputStream.cxx | 18 ++++++++++++------ src/input/BufferingInputStream.hxx | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/input/BufferingInputStream.cxx b/src/input/BufferingInputStream.cxx index 32ac0749c..817c37a9c 100644 --- a/src/input/BufferingInputStream.cxx +++ b/src/input/BufferingInputStream.cxx @@ -134,13 +134,9 @@ BufferingInputStream::FindFirstHole() const noexcept return INVALID_OFFSET; } -void -BufferingInputStream::RunThread() noexcept +inline void +BufferingInputStream::RunThreadLocked(std::unique_lock &lock) noexcept { - SetThreadName("buffering"); - - std::unique_lock lock(mutex); - while (!stop) { if (seek) { try { @@ -256,6 +252,16 @@ BufferingInputStream::RunThread() noexcept } else wake_cond.wait(lock); } +} + +void +BufferingInputStream::RunThread() noexcept +{ + SetThreadName("buffering"); + + std::unique_lock lock(mutex); + + RunThreadLocked(lock); /* clear the "input" attribute while holding the mutex */ auto _input = std::move(input); diff --git a/src/input/BufferingInputStream.hxx b/src/input/BufferingInputStream.hxx index ee460210c..0f1912c55 100644 --- a/src/input/BufferingInputStream.hxx +++ b/src/input/BufferingInputStream.hxx @@ -88,6 +88,7 @@ protected: private: size_t FindFirstHole() const noexcept; + void RunThreadLocked(std::unique_lock &lock) noexcept; void RunThread() noexcept; /* virtual methods from class InputStreamHandler */