Add a mutex on the loading jobs to protect them in the case of freewheeling

This commit is contained in:
Paul Ferrand 2020-10-15 14:30:15 +01:00
parent 8369f958dd
commit a5647ab339
2 changed files with 5 additions and 0 deletions

View file

@ -482,6 +482,7 @@ void sfz::FilePool::dispatchingJob() noexcept
}
// Clear finished jobs
std::lock_guard<SpinMutex> guard { loadingJobsMutex };
swapAndPopAll(loadingJobs, [](std::future<void>& future) {
return future.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
});
@ -515,8 +516,11 @@ void sfz::FilePool::emptyFileLoadingQueues() noexcept
void sfz::FilePool::waitForBackgroundLoading() noexcept
{
std::lock_guard<SpinMutex> guard { loadingJobsMutex };
for (auto& job : loadingJobs)
job.wait();
loadingJobs.clear();
}

View file

@ -354,6 +354,7 @@ private:
void dispatchingJob() noexcept;
void garbageJob() noexcept;
void loadingJob(QueuedFileData data) noexcept;
SpinMutex loadingJobsMutex;
std::vector<std::future<void>> loadingJobs;
std::thread dispatchThread { &FilePool::dispatchingJob, this };
std::thread garbageThread { &FilePool::garbageJob, this };