Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
b5c7c16f
Commit
b5c7c16f
authored
May 17, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/buffering: merge multiple exception handlers into RunThread()
parent
302c0515
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
52 deletions
+15
-52
BufferingInputStream.cxx
src/input/BufferingInputStream.cxx
+14
-51
BufferingInputStream.hxx
src/input/BufferingInputStream.hxx
+1
-1
No files found.
src/input/BufferingInputStream.cxx
View file @
b5c7c16f
...
...
@@ -135,7 +135,7 @@ BufferingInputStream::FindFirstHole() const noexcept
}
inline
void
BufferingInputStream
::
RunThreadLocked
(
std
::
unique_lock
<
Mutex
>
&
lock
)
noexcept
BufferingInputStream
::
RunThreadLocked
(
std
::
unique_lock
<
Mutex
>
&
lock
)
{
while
(
!
stop
)
{
if
(
seek
)
{
...
...
@@ -158,20 +158,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
reading position to be able to fill our
buffer */
try
{
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
;
}
input
->
Seek
(
lock
,
offset
);
}
else
if
(
input
->
IsEOF
())
{
/* our input has reached its end: prepare
reading the first remaining hole */
...
...
@@ -183,14 +170,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
}
/* seek to the first hole */
try
{
input
->
Seek
(
lock
,
new_offset
);
}
catch
(...)
{
read_error
=
std
::
current_exception
();
client_cond
.
notify_all
();
OnBufferAvailable
();
break
;
}
input
->
Seek
(
lock
,
new_offset
);
}
else
if
(
input
->
IsAvailable
())
{
const
auto
read_offset
=
input
->
GetOffset
();
auto
w
=
buffer
.
Write
(
read_offset
);
...
...
@@ -207,14 +187,7 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
read completely */
break
;
try
{
input
->
Seek
(
lock
,
new_offset
);
}
catch
(...)
{
read_error
=
std
::
current_exception
();
client_cond
.
notify_all
();
OnBufferAvailable
();
break
;
}
input
->
Seek
(
lock
,
new_offset
);
}
else
{
/* we need more data at our
current position, because
...
...
@@ -222,30 +195,14 @@ BufferingInputStream::RunThreadLocked(std::unique_lock<Mutex> &lock) noexcept
- seek our input to our
offset to prepare filling
the buffer from there */
try
{
input
->
Seek
(
lock
,
offset
);
}
catch
(...)
{
read_error
=
std
::
current_exception
();
client_cond
.
notify_all
();
OnBufferAvailable
();
break
;
}
input
->
Seek
(
lock
,
offset
);
}
continue
;
}
try
{
size_t
nbytes
=
input
->
Read
(
lock
,
w
.
data
,
w
.
size
);
buffer
.
Commit
(
read_offset
,
read_offset
+
nbytes
);
}
catch
(...)
{
read_error
=
std
::
current_exception
();
client_cond
.
notify_all
();
OnBufferAvailable
();
break
;
}
size_t
nbytes
=
input
->
Read
(
lock
,
w
.
data
,
w
.
size
);
buffer
.
Commit
(
read_offset
,
read_offset
+
nbytes
);
client_cond
.
notify_all
();
OnBufferAvailable
();
...
...
@@ -261,7 +218,13 @@ BufferingInputStream::RunThread() noexcept
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 */
auto
_input
=
std
::
move
(
input
);
...
...
src/input/BufferingInputStream.hxx
View file @
b5c7c16f
...
...
@@ -88,7 +88,7 @@ protected:
private
:
size_t
FindFirstHole
()
const
noexcept
;
void
RunThreadLocked
(
std
::
unique_lock
<
Mutex
>
&
lock
)
noexcept
;
void
RunThreadLocked
(
std
::
unique_lock
<
Mutex
>
&
lock
);
void
RunThread
()
noexcept
;
/* virtual methods from class InputStreamHandler */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment