diff options
author | Max Kellermann <max@duempel.org> | 2016-06-17 18:30:45 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2016-06-17 18:31:58 +0200 |
commit | 5d11759f7dece5ebc637a03a12825bdd1012e304 (patch) | |
tree | 108021d383bec3b630e639ed23140c4989675699 /src/input/AsyncInputStream.cxx | |
parent | 829616534e0cd560bda55252b54d497c76ef77c1 (diff) |
input/async: use class DeferredCall
Diffstat (limited to 'src/input/AsyncInputStream.cxx')
-rw-r--r-- | src/input/AsyncInputStream.cxx | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/input/AsyncInputStream.cxx b/src/input/AsyncInputStream.cxx index f351bbc38..4c80e8e57 100644 --- a/src/input/AsyncInputStream.cxx +++ b/src/input/AsyncInputStream.cxx @@ -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(); +} - if (seek_state == SeekState::SCHEDULED) { - seek_state = SeekState::PENDING; - buffer.Clear(); - paused = false; - DoSeek(seek_offset); - } +void +AsyncInputStream::DeferredSeek() +{ + const ScopeLock protect(mutex); + if (seek_state != SeekState::SCHEDULED) + return; + + Resume(); + + seek_state = SeekState::PENDING; + buffer.Clear(); + paused = false; + DoSeek(seek_offset); } |