Upon clearing the file pool, clear the last used files and garbage queue

I also added an early exit with an assertion to catch unintended behavior
This commit is contained in:
Paul Ferrand 2020-10-23 14:47:10 +02:00
parent a372d40c48
commit 1d2c3a4244

View file

@ -435,7 +435,10 @@ void sfz::FilePool::loadingJob(QueuedFileData data) noexcept
void sfz::FilePool::clear()
{
std::lock_guard<SpinMutex> guard { garbageAndLastUsedMutex };
emptyFileLoadingQueues();
garbageToCollect.clear();
lastUsedFiles.clear();
preloadedFiles.clear();
}
@ -593,7 +596,15 @@ void sfz::FilePool::triggerGarbageCollection() noexcept
if (garbageToCollect.size() == garbageToCollect.capacity())
return false;
auto& data = preloadedFiles[id];
auto it = preloadedFiles.find(id);
if (it == preloadedFiles.end()) {
// Getting here means that the preloadedFiles got changed (probably cleared)
// while the lastUsedFiles were untouched.
ASSERTFALSE;
return true;
}
sfz::FileData& data = it->second;
if (data.status == FileData::Status::Preloaded)
return true;