aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/hrtf.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-06-24 12:55:36 -0700
committerChris Robinson <[email protected]>2019-06-24 12:55:36 -0700
commite8cef0cdae5675f3d23f0de9e9093734c74ababb (patch)
tree847706628702a1ceb65299aa2813867428dd0dea /Alc/hrtf.cpp
parentb46fc572f598bfa917c8cd7f3c099cb218962dd1 (diff)
Clean up all unused HRTFs when going through them
Diffstat (limited to 'Alc/hrtf.cpp')
-rw-r--r--Alc/hrtf.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp
index 2584ef13..6b3edd9f 100644
--- a/Alc/hrtf.cpp
+++ b/Alc/hrtf.cpp
@@ -1376,18 +1376,16 @@ void HrtfEntry::DecRef()
{
std::lock_guard<std::mutex> _{LoadedHrtfLock};
- /* Need to double-check that it's still unused, as another device
- * could've reacquired this HRTF after its reference went to 0 and
- * before the lock was taken.
- */
- auto iter = std::find_if(LoadedHrtfs.begin(), LoadedHrtfs.end(),
- [this](const HrtfHandlePtr &entry) noexcept -> bool
- { return this == entry->entry.get(); }
- );
- if(iter != LoadedHrtfs.end() && ReadRef(&this->ref) == 0)
+ /* Go through and clear all unused HRTFs. */
+ auto delete_unused = [](HrtfHandlePtr &handle) -> void
{
- (*iter)->entry = nullptr;
- TRACE("Unloaded unused HRTF %s\n", (*iter)->filename.data());
- }
+ HrtfEntry *entry{handle->entry.get()};
+ if(entry && ReadRef(&entry->ref) == 0)
+ {
+ TRACE("Unloading unused HRTF %s\n", handle->filename.data());
+ handle->entry = nullptr;
+ }
+ };
+ std::for_each(LoadedHrtfs.begin(), LoadedHrtfs.end(), delete_unused);
}
}