This commit is contained in:
parent
dd719fe134
commit
1c48b963a6
@ -103,14 +103,18 @@ auto ring_buffer_base::download_chunk(std::size_t chunk, bool skip_active)
|
|||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
unique_mutex_lock chunk_lock(chunk_mtx_);
|
unique_mutex_lock chunk_lock(chunk_mtx_);
|
||||||
const auto unlock_and_notify = [this, &chunk_lock]() {
|
if (not skip_active) {
|
||||||
|
ring_pos_ = chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto notify_and_unlock = [this, &chunk_lock]() {
|
||||||
chunk_notify_.notify_all();
|
chunk_notify_.notify_all();
|
||||||
chunk_lock.unlock();
|
chunk_lock.unlock();
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto unlock_and_return =
|
const auto unlock_and_return =
|
||||||
[&unlock_and_notify](api_error res) -> api_error {
|
[¬ify_and_unlock](api_error res) -> api_error {
|
||||||
unlock_and_notify();
|
notify_and_unlock();
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -124,7 +128,7 @@ auto ring_buffer_base::download_chunk(std::size_t chunk, bool skip_active)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto active_download = get_active_downloads().at(chunk);
|
auto active_download = get_active_downloads().at(chunk);
|
||||||
unlock_and_notify();
|
notify_and_unlock();
|
||||||
|
|
||||||
return active_download->wait();
|
return active_download->wait();
|
||||||
}
|
}
|
||||||
@ -142,7 +146,7 @@ auto ring_buffer_base::download_chunk(std::size_t chunk, bool skip_active)
|
|||||||
chunk == (total_chunks_ - 1U) ? get_last_chunk_size()
|
chunk == (total_chunks_ - 1U) ? get_last_chunk_size()
|
||||||
: get_chunk_size(),
|
: get_chunk_size(),
|
||||||
};
|
};
|
||||||
unlock_and_notify();
|
notify_and_unlock();
|
||||||
|
|
||||||
auto result{
|
auto result{
|
||||||
get_provider().read_file_bytes(get_api_path(), data_size, data_offset,
|
get_provider().read_file_bytes(get_api_path(), data_size, data_offset,
|
||||||
@ -167,7 +171,7 @@ auto ring_buffer_base::download_chunk(std::size_t chunk, bool skip_active)
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_active_downloads().erase(chunk);
|
get_active_downloads().erase(chunk);
|
||||||
unlock_and_notify();
|
notify_and_unlock();
|
||||||
|
|
||||||
active_download->notify(result);
|
active_download->notify(result);
|
||||||
return result;
|
return result;
|
||||||
@ -225,10 +229,7 @@ auto ring_buffer_base::read(std::size_t read_size, std::uint64_t read_offset,
|
|||||||
forward(chunk - ring_pos_);
|
forward(chunk - ring_pos_);
|
||||||
} else if (chunk < ring_pos_) {
|
} else if (chunk < ring_pos_) {
|
||||||
reverse(ring_pos_ - chunk);
|
reverse(ring_pos_ - chunk);
|
||||||
} else {
|
|
||||||
ring_pos_ = chunk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = download_chunk(chunk, false);
|
res = download_chunk(chunk, false);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
if (res == api_error::invalid_ring_buffer_position) {
|
if (res == api_error::invalid_ring_buffer_position) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user