From 8b84e5b3f975e4ad692b7cdcb1b7212b41f25cf1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 17 Jun 2014 00:52:12 +0200 Subject: input/curl: hold mutex while writing to postponed_error --- src/input/AsyncInputStream.cxx | 10 ++++++++++ src/input/AsyncInputStream.hxx | 2 ++ src/input/plugins/CurlInputPlugin.cxx | 7 ++++--- 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/input') diff --git a/src/input/AsyncInputStream.cxx b/src/input/AsyncInputStream.cxx index 169a9e8e4..f2e0320c4 100644 --- a/src/input/AsyncInputStream.cxx +++ b/src/input/AsyncInputStream.cxx @@ -63,6 +63,16 @@ AsyncInputStream::Pause() paused = true; } +void +AsyncInputStream::PostponeError(Error &&error) +{ + assert(io_thread_inside()); + + seek_state = SeekState::NONE; + postponed_error = std::move(error); + cond.broadcast(); +} + inline void AsyncInputStream::Resume() { diff --git a/src/input/AsyncInputStream.hxx b/src/input/AsyncInputStream.hxx index a2945be81..c2055c17d 100644 --- a/src/input/AsyncInputStream.hxx +++ b/src/input/AsyncInputStream.hxx @@ -86,6 +86,8 @@ protected: open = false; } + void PostponeError(Error &&error); + bool IsBufferEmpty() const { return buffer.IsEmpty(); } diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index 2450c8754..46961d08f 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -777,9 +777,10 @@ CurlInputStream::DoSeek(offset_type new_offset) return; } + Error error; if (!InitEasy(postponed_error)) { mutex.lock(); - SeekDone(); + PostponeError(std::move(error)); return; } @@ -790,9 +791,9 @@ CurlInputStream::DoSeek(offset_type new_offset) curl_easy_setopt(easy, CURLOPT_RANGE, range); } - if (!input_curl_easy_add_indirect(this, postponed_error)) { + if (!input_curl_easy_add_indirect(this, error)) { mutex.lock(); - SeekDone(); + PostponeError(std::move(error)); return; } -- cgit v1.2.3