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
5d11759f
Commit
5d11759f
authored
Jun 17, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/async: use class DeferredCall
parent
82961653
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
AsyncInputStream.cxx
src/input/AsyncInputStream.cxx
+16
-6
AsyncInputStream.hxx
src/input/AsyncInputStream.hxx
+8
-4
No files found.
src/input/AsyncInputStream.cxx
View file @
5d11759f
...
...
@@ -31,7 +31,9 @@ AsyncInputStream::AsyncInputStream(const char *_url,
Mutex
&
_mutex
,
Cond
&
_cond
,
size_t
_buffer_size
,
size_t
_resume_at
)
:
InputStream
(
_url
,
_mutex
,
_cond
),
DeferredMonitor
(
io_thread_get
()),
:
InputStream
(
_url
,
_mutex
,
_cond
),
deferred_resume
(
io_thread_get
(),
BIND_THIS_METHOD
(
DeferredResume
)),
deferred_seek
(
io_thread_get
(),
BIND_THIS_METHOD
(
DeferredSeek
)),
allocation
(
_buffer_size
),
buffer
((
uint8_t
*
)
allocation
.
get
(),
_buffer_size
),
resume_at
(
_resume_at
),
...
...
@@ -141,7 +143,7 @@ AsyncInputStream::Seek(offset_type new_offset, Error &error)
seek_offset
=
new_offset
;
seek_state
=
SeekState
::
SCHEDULED
;
DeferredMonitor
::
Schedule
();
deferred_seek
.
Schedule
();
while
(
seek_state
!=
SeekState
::
NONE
)
cond
.
wait
(
mutex
);
...
...
@@ -208,7 +210,7 @@ AsyncInputStream::Read(void *ptr, size_t read_size, Error &error)
offset
+=
(
offset_type
)
nbytes
;
if
(
paused
&&
buffer
.
GetSize
()
<
resume_at
)
DeferredMonitor
::
Schedule
();
deferred_resume
.
Schedule
();
return
nbytes
;
}
...
...
@@ -240,16 +242,24 @@ AsyncInputStream::AppendToBuffer(const void *data, size_t append_size)
}
void
AsyncInputStream
::
RunDeferred
()
AsyncInputStream
::
DeferredResume
()
{
const
ScopeLock
protect
(
mutex
);
Resume
();
}
void
AsyncInputStream
::
DeferredSeek
()
{
const
ScopeLock
protect
(
mutex
);
if
(
seek_state
!=
SeekState
::
SCHEDULED
)
return
;
Resume
();
if
(
seek_state
==
SeekState
::
SCHEDULED
)
{
seek_state
=
SeekState
::
PENDING
;
buffer
.
Clear
();
paused
=
false
;
DoSeek
(
seek_offset
);
}
}
src/input/AsyncInputStream.hxx
View file @
5d11759f
...
...
@@ -21,7 +21,7 @@
#define MPD_ASYNC_INPUT_STREAM_HXX
#include "InputStream.hxx"
#include "event/Deferred
Monitor
.hxx"
#include "event/Deferred
Call
.hxx"
#include "util/HugeAllocator.hxx"
#include "util/CircularBuffer.hxx"
#include "util/Error.hxx"
...
...
@@ -32,11 +32,14 @@
* buffer, and that buffer is then consumed by another thread using
* the regular #InputStream API.
*/
class
AsyncInputStream
:
public
InputStream
,
private
DeferredMonitor
{
class
AsyncInputStream
:
public
InputStream
{
enum
class
SeekState
:
uint8_t
{
NONE
,
SCHEDULED
,
PENDING
};
DeferredCall
deferred_resume
;
DeferredCall
deferred_seek
;
HugeAllocation
allocation
;
CircularBuffer
<
uint8_t
>
buffer
;
...
...
@@ -162,8 +165,9 @@ protected:
private
:
void
Resume
();
/* virtual methods from DeferredMonitor */
void
RunDeferred
()
final
;
/* for DeferredCall */
void
DeferredResume
();
void
DeferredSeek
();
};
#endif
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