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