From 17236412e3f2be9ffd8416d09a96ae1fdb530107 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sat, 30 Nov 2019 16:17:10 +0100 Subject: [PATCH] Added a signal that the filepool should empty the queue --- src/sfizz/FilePool.cpp | 8 +++++++- src/sfizz/FilePool.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index 9acec5e7..200bb285 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -112,6 +112,12 @@ void sfz::FilePool::enqueueLoading(Voice* voice, const std::string* sample, int void sfz::FilePool::loadingThread() noexcept { while (!quitThread) { + if (emptyQueue) { + while(loadingQueue.pop()) {} + emptyQueue = false; + continue; + } + FileLoadingInformation fileToLoad {}; if (!loadingQueue.wait_dequeue_timed(fileToLoad, 200ms)) { continue; @@ -135,7 +141,7 @@ void sfz::FilePool::loadingThread() noexcept } SndfileHandle sndFile(reinterpret_cast(file.c_str())); - + std::lock_guard guard { fileHandleMutex }; fileHandles.emplace_back(readFromFile(sndFile, fileToLoad.numFrames)); fileToLoad.voice->setFileData(fileHandles.back(), fileToLoad.ticket); diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index 3c088dce..d90ffc54 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -113,6 +113,8 @@ public: * */ void clear(); + void emptyFileLoadingQueue() noexcept { emptyQueue = true; } + bool shouldEmptyQueue() const noexcept { return emptyQueue; } private: fs::path rootDirectory; struct FileLoadingInformation { @@ -126,6 +128,7 @@ private: void loadingThread() noexcept; void garbageThread() noexcept; bool quitThread { false }; + bool emptyQueue { false }; std::mutex fileHandleMutex; std::vector>> fileHandles; absl::flat_hash_map>> preloadedData;