Commit b5c7c16f authored by Max Kellermann's avatar Max Kellermann

input/buffering: merge multiple exception handlers into RunThread()

parent 302c0515
...@@ -135,7 +135,7 @@ BufferingInputStream::FindFirstHole() const noexcept ...@@ -135,7 +135,7 @@ BufferingInputStream::FindFirstHole() const noexcept
} }
inline void inline void
BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock)
{ {
while (!stop) { while (!stop) {
if (seek) { if (seek) {
...@@ -158,20 +158,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept ...@@ -158,20 +158,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
reading position to be able to fill our reading position to be able to fill our
buffer */ buffer */
try { input->Seek(lock, offset);
input->Seek(lock, offset);
} catch (...) {
/* this is really a seek error, but we
register it as a read_error,
because seek_error is only checked
by Seek(), and at our frontend (our
own InputStream interface) is in
"read" mode */
read_error = std::current_exception();
client_cond.notify_all();
OnBufferAvailable();
break;
}
} else if (input->IsEOF()) { } else if (input->IsEOF()) {
/* our input has reached its end: prepare /* our input has reached its end: prepare
reading the first remaining hole */ reading the first remaining hole */
...@@ -183,14 +170,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept ...@@ -183,14 +170,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
} }
/* seek to the first hole */ /* seek to the first hole */
try { input->Seek(lock, new_offset);
input->Seek(lock, new_offset);
} catch (...) {
read_error = std::current_exception();
client_cond.notify_all();
OnBufferAvailable();
break;
}
} else if (input->IsAvailable()) { } else if (input->IsAvailable()) {
const auto read_offset = input->GetOffset(); const auto read_offset = input->GetOffset();
auto w = buffer.Write(read_offset); auto w = buffer.Write(read_offset);
...@@ -207,14 +187,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept ...@@ -207,14 +187,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
read completely */ read completely */
break; break;
try { input->Seek(lock, new_offset);
input->Seek(lock, new_offset);
} catch (...) {
read_error = std::current_exception();
client_cond.notify_all();
OnBufferAvailable();
break;
}
} else { } else {
/* we need more data at our /* we need more data at our
current position, because current position, because
...@@ -222,30 +195,14 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept ...@@ -222,30 +195,14 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
- seek our input to our - seek our input to our
offset to prepare filling offset to prepare filling
the buffer from there */ the buffer from there */
try { input->Seek(lock, offset);
input->Seek(lock, offset);
} catch (...) {
read_error = std::current_exception();
client_cond.notify_all();
OnBufferAvailable();
break;
}
} }
continue; continue;
} }
try { size_t nbytes = input->Read(lock, w.data, w.size);
size_t nbytes = input->Read(lock, buffer.Commit(read_offset, read_offset + nbytes);
w.data, w.size);
buffer.Commit(read_offset,
read_offset + nbytes);
} catch (...) {
read_error = std::current_exception();
client_cond.notify_all();
OnBufferAvailable();
break;
}
client_cond.notify_all(); client_cond.notify_all();
OnBufferAvailable(); OnBufferAvailable();
...@@ -261,7 +218,13 @@ BufferingInputStream::RunThread() noexcept ...@@ -261,7 +218,13 @@ BufferingInputStream::RunThread() noexcept
std::unique_lock<Mutex> lock(mutex); std::unique_lock<Mutex> lock(mutex);
RunThreadLocked(lock); try {
RunThreadLocked(lock);
} catch (...) {
read_error = std::current_exception();
client_cond.notify_all();
OnBufferAvailable();
}
/* 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);
......
...@@ -88,7 +88,7 @@ protected: ...@@ -88,7 +88,7 @@ protected:
private: private:
size_t FindFirstHole() const noexcept; size_t FindFirstHole() const noexcept;
void RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept; void RunThreadLocked(std::unique_lock<Mutex> &lock);
void RunThread() noexcept; void RunThread() noexcept;
/* virtual methods from class InputStreamHandler */ /* virtual methods from class InputStreamHandler */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment