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(); } }