This commit is contained in:
@ -256,33 +256,6 @@ auto ring_buffer_open_file::native_operation(
|
||||
return do_io([&]() -> api_error { return callback(nf_->get_handle()); });
|
||||
}
|
||||
|
||||
void ring_buffer_open_file::reverse(std::size_t count) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
count = std::min(ring_pos_, count);
|
||||
|
||||
if ((ring_pos_ - count) >= ring_begin_) {
|
||||
ring_pos_ -= count;
|
||||
} else {
|
||||
auto removed = count - (ring_pos_ - ring_begin_);
|
||||
if (removed >= ring_state_.size()) {
|
||||
ring_state_.set(0U, ring_state_.size(), false);
|
||||
ring_pos_ -= count;
|
||||
ring_begin_ = ring_pos_;
|
||||
} else {
|
||||
for (std::size_t idx = 0U; idx < removed; ++idx) {
|
||||
ring_state_[(ring_end_ - idx) % ring_state_.size()] = false;
|
||||
}
|
||||
ring_begin_ -= removed;
|
||||
ring_pos_ -= count;
|
||||
}
|
||||
|
||||
ring_end_ =
|
||||
std::min(total_chunks_ - 1U, ring_begin_ + ring_state_.size() - 1U);
|
||||
}
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::read(std::size_t read_size,
|
||||
std::uint64_t read_offset,
|
||||
data_buffer &data) -> api_error {
|
||||
@ -412,6 +385,33 @@ void ring_buffer_open_file::reader_thread() {
|
||||
api_error::download_stopped);
|
||||
}
|
||||
|
||||
void ring_buffer_open_file::reverse(std::size_t count) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
count = std::min(ring_pos_, count);
|
||||
|
||||
if ((ring_pos_ - count) >= ring_begin_) {
|
||||
ring_pos_ -= count;
|
||||
} else {
|
||||
auto removed = count - (ring_pos_ - ring_begin_);
|
||||
if (removed >= ring_state_.size()) {
|
||||
ring_state_.set(0U, ring_state_.size(), false);
|
||||
ring_pos_ -= count;
|
||||
ring_begin_ = ring_pos_;
|
||||
} else {
|
||||
for (std::size_t idx = 0U; idx < removed; ++idx) {
|
||||
ring_state_[(ring_end_ - idx) % ring_state_.size()] = false;
|
||||
}
|
||||
ring_begin_ -= removed;
|
||||
ring_pos_ -= count;
|
||||
}
|
||||
|
||||
ring_end_ =
|
||||
std::min(total_chunks_ - 1U, ring_begin_ + ring_state_.size() - 1U);
|
||||
}
|
||||
|
||||
chunk_notify_.notify_all();
|
||||
}
|
||||
|
||||
void ring_buffer_open_file::set(std::size_t first_chunk,
|
||||
std::size_t current_chunk) {
|
||||
mutex_lock chunk_lock(chunk_mtx_);
|
||||
|
Reference in New Issue
Block a user