Add a mutex on the loading jobs to protect them in the case of freewheeling
This commit is contained in:
parent
8369f958dd
commit
a5647ab339
2 changed files with 5 additions and 0 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue