input/buffering: move code to RunThreadLocked()

This commit is contained in:
Max Kellermann 2019-05-17 11:21:56 +02:00
parent 19e4672a54
commit 302c0515b7
2 changed files with 13 additions and 6 deletions

View File

@ -134,13 +134,9 @@ BufferingInputStream::FindFirstHole() const noexcept
return INVALID_OFFSET; return INVALID_OFFSET;
} }
void inline void
BufferingInputStream::RunThread() noexcept BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
{ {
SetThreadName("buffering");
std::unique_lock<Mutex> lock(mutex);
while (!stop) { while (!stop) {
if (seek) { if (seek) {
try { try {
@ -256,6 +252,16 @@ BufferingInputStream::RunThread() noexcept
} else } else
wake_cond.wait(lock); wake_cond.wait(lock);
} }
}
void
BufferingInputStream::RunThread() noexcept
{
SetThreadName("buffering");
std::unique_lock<Mutex> lock(mutex);
RunThreadLocked(lock);
/* clear the "input" attribute while holding the mutex */ /* clear the "input" attribute while holding the mutex */
auto _input = std::move(input); auto _input = std::move(input);

View File

@ -88,6 +88,7 @@ protected:
private: private:
size_t FindFirstHole() const noexcept; size_t FindFirstHole() const noexcept;
void RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept;
void RunThread() noexcept; void RunThread() noexcept;
/* virtual methods from class InputStreamHandler */ /* virtual methods from class InputStreamHandler */