Added a signal that the filepool should empty the queue
This commit is contained in:
parent
ffda6626e2
commit
17236412e3
2 changed files with 10 additions and 1 deletions
|
|
@ -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<const char*>(file.c_str()));
|
||||
|
||||
|
||||
std::lock_guard<std::mutex> guard { fileHandleMutex };
|
||||
fileHandles.emplace_back(readFromFile<float>(sndFile, fileToLoad.numFrames));
|
||||
fileToLoad.voice->setFileData(fileHandles.back(), fileToLoad.ticket);
|
||||
|
|
|
|||
|
|
@ -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<std::shared_ptr<AudioBuffer<float>>> fileHandles;
|
||||
absl::flat_hash_map<absl::string_view, std::shared_ptr<AudioBuffer<float>>> preloadedData;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue