This commit is contained in:
parent
ab07d7e192
commit
2952cc8373
@ -309,11 +309,10 @@ void open_file::download_chunk(std::size_t chunk, bool skip_active,
|
||||
|
||||
void open_file::download_range(std::size_t start_chunk, std::size_t end_chunk,
|
||||
bool should_reset) {
|
||||
for (std::size_t chunk = start_chunk; chunk <= end_chunk; ++chunk) {
|
||||
for (std::size_t chunk = start_chunk;
|
||||
(get_api_error() == api_error::success) && (chunk <= end_chunk);
|
||||
++chunk) {
|
||||
download_chunk(chunk, false, should_reset);
|
||||
if (get_api_error() != api_error::success) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -558,35 +557,36 @@ void open_file::update_background_reader(std::size_t read_chunk) {
|
||||
recur_mutex_lock reader_lock(file_mtx_);
|
||||
read_chunk_ = read_chunk;
|
||||
|
||||
if (not reader_thread_ && not stop_requested_) {
|
||||
reader_thread_ = std::make_unique<std::thread>([this]() {
|
||||
std::size_t next_chunk{};
|
||||
while (not stop_requested_) {
|
||||
unique_recur_mutex_lock file_lock(file_mtx_);
|
||||
if ((fsi_.size == 0U) || read_state_.all()) {
|
||||
file_lock.unlock();
|
||||
|
||||
unique_mutex_lock io_lock(io_thread_mtx_);
|
||||
if (not stop_requested_ && io_thread_queue_.empty()) {
|
||||
io_thread_notify_.wait(io_lock);
|
||||
}
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
next_chunk = read_chunk_ = ((read_chunk_ + 1U) >= read_state_.size())
|
||||
? 0U
|
||||
: read_chunk_ + 1U;
|
||||
} while ((next_chunk != 0U) && (active_downloads_.find(next_chunk) !=
|
||||
active_downloads_.end()));
|
||||
|
||||
file_lock.unlock();
|
||||
download_chunk(next_chunk, true, false);
|
||||
}
|
||||
});
|
||||
if (reader_thread_ || stop_requested_) {
|
||||
return;
|
||||
}
|
||||
|
||||
reader_thread_ = std::make_unique<std::thread>([this]() {
|
||||
std::size_t next_chunk{};
|
||||
while (not stop_requested_) {
|
||||
unique_recur_mutex_lock file_lock(file_mtx_);
|
||||
if ((fsi_.size == 0U) || read_state_.all()) {
|
||||
file_lock.unlock();
|
||||
|
||||
unique_mutex_lock io_lock(io_thread_mtx_);
|
||||
if (not stop_requested_ && io_thread_queue_.empty()) {
|
||||
io_thread_notify_.wait(io_lock);
|
||||
}
|
||||
io_thread_notify_.notify_all();
|
||||
io_lock.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
next_chunk = read_chunk_ =
|
||||
((read_chunk_ + 1U) >= read_state_.size()) ? 0U : read_chunk_ + 1U;
|
||||
} while ((next_chunk != 0U) &&
|
||||
(active_downloads_.find(next_chunk) != active_downloads_.end()));
|
||||
|
||||
file_lock.unlock();
|
||||
download_chunk(next_chunk, true, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
auto open_file::write(std::uint64_t write_offset, const data_buffer &data,
|
||||
|
Loading…
x
Reference in New Issue
Block a user