From 1a84e507fc864c29851365e37e3c961135347c68 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 23 Dec 2024 08:54:01 -0600 Subject: [PATCH] Complete ring buffer and direct download support #26 --- .../src/file_manager/ring_buffer_open_file.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/repertory/librepertory/src/file_manager/ring_buffer_open_file.cpp b/repertory/librepertory/src/file_manager/ring_buffer_open_file.cpp index 3f3f8c1f..5723d16e 100644 --- a/repertory/librepertory/src/file_manager/ring_buffer_open_file.cpp +++ b/repertory/librepertory/src/file_manager/ring_buffer_open_file.cpp @@ -112,6 +112,12 @@ void ring_buffer_open_file::background_reader_thread() { next_chunk = next_chunk + 1U > ring_end_ ? ring_begin_ : next_chunk + 1U; const auto check_and_wait = [this, &chunk_lock, &next_chunk]() { + if (stop_requested_) { + chunk_notify_.notify_all(); + chunk_lock.unlock(); + return; + } + if (get_read_state().all()) { chunk_notify_.wait(chunk_lock); next_chunk = ring_pos_; @@ -130,6 +136,9 @@ void ring_buffer_open_file::background_reader_thread() { chunk_lock.unlock(); download_chunk(next_chunk, true); + + chunk_lock.lock(); + check_and_wait(); } }