Complete ring buffer and direct download support #26
This commit is contained in:
parent
f344665ddc
commit
ad22233308
@ -373,33 +373,31 @@ void ring_buffer_open_file::set_api_path(const std::string &api_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ring_buffer_open_file::background_reader_thread() {
|
void ring_buffer_open_file::background_reader_thread() {
|
||||||
unique_mutex_lock read_lock(read_mtx_);
|
unique_mutex_lock chunk_lock(chunk_mtx_);
|
||||||
read_lock.unlock();
|
|
||||||
|
|
||||||
auto next_chunk = ring_pos_;
|
auto next_chunk = ring_pos_;
|
||||||
while (not stop_requested_) {
|
chunk_notify_.notify_all();
|
||||||
read_lock.lock();
|
chunk_lock.unlock();
|
||||||
|
|
||||||
const auto check_and_wait = [this, &next_chunk]() {
|
while (not stop_requested_) {
|
||||||
unique_mutex_lock chunk_lock(chunk_mtx_);
|
chunk_lock.lock();
|
||||||
|
|
||||||
|
next_chunk = next_chunk + 1U > ring_end_ ? ring_begin_ : next_chunk + 1U;
|
||||||
|
const auto check_and_wait = [this, &chunk_lock, &next_chunk]() {
|
||||||
if (get_read_state().all()) {
|
if (get_read_state().all()) {
|
||||||
chunk_notify_.wait(chunk_lock);
|
chunk_notify_.wait(chunk_lock);
|
||||||
next_chunk = ring_pos_;
|
next_chunk = ring_pos_;
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk_notify_.notify_all();
|
chunk_notify_.notify_all();
|
||||||
|
chunk_lock.unlock();
|
||||||
};
|
};
|
||||||
|
|
||||||
next_chunk = next_chunk + 1U > ring_end_ ? ring_begin_ : next_chunk + 1U;
|
|
||||||
if (not ring_state_[next_chunk % ring_state_.size()]) {
|
if (not ring_state_[next_chunk % ring_state_.size()]) {
|
||||||
read_lock.unlock();
|
|
||||||
|
|
||||||
check_and_wait();
|
check_and_wait();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_lock.unlock();
|
|
||||||
download_chunk(next_chunk, true);
|
download_chunk(next_chunk, true);
|
||||||
|
|
||||||
check_and_wait();
|
check_and_wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user