[Conformance cache] Add allocated extended-storage for entries to the free list

This memory is part of the conformance cache concurrent hash map, so
when we clear the conformance cache, record each of the allocated
pointers within the concurrent map's free list. This way, it'll be
freed with the rest of the concurrent map when it's safe to do so.
This commit is contained in:
Doug Gregor
2025-04-16 15:11:59 -07:00
parent d576fa30c9
commit 885f829a63
2 changed files with 50 additions and 8 deletions

View File

@@ -750,7 +750,12 @@ public:
/// Clear the hash table, freeing (when safe) all memory currently used for
/// indices and elements.
void clear() {
///
/// - addFreedNodes: if nonempty, this function will be called with the head
/// of the free list. The function may add additional nodes to the free
/// list, which will be freed when it is safe to do so.
void clear(std::function<void(ConcurrentFreeListNode *&)> addFreedNodes
= nullptr) {
typename MutexTy::ScopedLock guard(WriterLock);
IndexStorage indices = Indices.load(std::memory_order_relaxed);
@@ -766,6 +771,9 @@ public:
ConcurrentFreeListNode::add(&FreeList, ptr);
ConcurrentFreeListNode::add(&FreeList, elements);
if (addFreedNodes)
addFreedNodes(FreeList);
deallocateFreeListIfSafe();
}
};