diff --git a/repertory/librepertory/src/file_manager/ring_buffer_base.cpp b/repertory/librepertory/src/file_manager/ring_buffer_base.cpp index 39993d74..0db0ab60 100644 --- a/repertory/librepertory/src/file_manager/ring_buffer_base.cpp +++ b/repertory/librepertory/src/file_manager/ring_buffer_base.cpp @@ -103,14 +103,18 @@ auto ring_buffer_base::download_chunk(std::size_t chunk, bool skip_active) REPERTORY_USES_FUNCTION_NAME(); 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_lock.unlock(); }; const auto unlock_and_return = - [&unlock_and_notify](api_error res) -> api_error { - unlock_and_notify(); + [¬ify_and_unlock](api_error res) -> api_error { + notify_and_unlock(); 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); - unlock_and_notify(); + notify_and_unlock(); 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() : get_chunk_size(), }; - unlock_and_notify(); + notify_and_unlock(); auto result{ 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); - unlock_and_notify(); + notify_and_unlock(); active_download->notify(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_); } else if (chunk < ring_pos_) { reverse(ring_pos_ - chunk); - } else { - ring_pos_ = chunk; } - res = download_chunk(chunk, false); if (res != api_error::success) { if (res == api_error::invalid_ring_buffer_position) {