diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index db1a1dfb..3177018b 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -428,7 +428,7 @@ void sfz::FilePool::loadingJob(QueuedFileData data) noexcept data.data->status = FileData::Status::Done; - std::lock_guard guard { lastUsedMutex }; + std::lock_guard guard { garbageAndLastUsedMutex }; if (absl::c_find(lastUsedFiles, *id) == lastUsedFiles.end()) lastUsedFiles.push_back(*id); } @@ -514,10 +514,7 @@ void sfz::FilePool::dispatchingJob() noexcept void sfz::FilePool::garbageJob() noexcept { while (semGarbageBarrier.wait(), garbageFlag) { - std::lock_guard guard { garbageMutex }; - for (auto& g: garbageToCollect) - g.reset(); - + std::lock_guard guard { garbageAndLastUsedMutex }; garbageToCollect.clear(); } } @@ -587,9 +584,8 @@ void sfz::FilePool::setRamLoading(bool loadInRam) noexcept void sfz::FilePool::triggerGarbageCollection() noexcept { - const std::unique_lock lastUsedLock { lastUsedMutex, std::try_to_lock }; - const std::unique_lock garbageLock { garbageMutex, std::try_to_lock }; - if (!lastUsedLock.owns_lock() || !garbageLock.owns_lock()) + const std::unique_lock guard { garbageAndLastUsedMutex, std::try_to_lock }; + if (!guard.owns_lock()) return; const auto now = std::chrono::high_resolution_clock::now(); diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index 8c14f1ce..41068598 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -362,9 +362,8 @@ private: std::thread dispatchThread { &FilePool::dispatchingJob, this }; std::thread garbageThread { &FilePool::garbageJob, this }; - SpinMutex lastUsedMutex; + SpinMutex garbageAndLastUsedMutex; std::vector lastUsedFiles; - SpinMutex garbageMutex; std::vector garbageToCollect; std::shared_ptr threadPool;