From ffaed1581a8645d0346a22b15b8cca8aa6a96600 Mon Sep 17 00:00:00 2001 From: KIRA Ryouta Date: Fri, 16 Feb 2024 11:16:58 +0900 Subject: [PATCH] Improved check for garbage collection --- src/sfizz/FilePool.cpp | 6 +++++- src/sfizz/FilePool.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index c5f12ab6..37dc2ff2 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #if defined(_WIN32) #include #else @@ -514,7 +515,10 @@ void sfz::FilePool::loadingJob(const QueuedFileData& data) noexcept } // wait for garbage collection if (currentStatus == FileData::Status::GarbageCollecting) { - std::this_thread::sleep_for(std::chrono::microseconds(1)); + atomic_queue::spin_loop_pause(); + atomic_queue::spin_loop_pause(); + atomic_queue::spin_loop_pause(); + atomic_queue::spin_loop_pause(); continue; } // Already loading or loaded diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index 5eceda2c..02f3d3eb 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -76,7 +76,8 @@ struct FileData } AudioSpan getData() { - if (availableFrames > preloadedData.getNumFrames()) + ASSERT(readerCount > 0); + if (status != Status::GarbageCollecting && availableFrames > preloadedData.getNumFrames()) return AudioSpan(fileData).first(availableFrames); else return AudioSpan(preloadedData);