Fix up checking for empty to account for stub messages.
This commit is contained in:
@@ -107,41 +107,43 @@ namespace snmalloc
|
||||
#endif
|
||||
}
|
||||
|
||||
void debug_check_empty()
|
||||
/**
|
||||
If you pass a pointer to a bool, then it returns whether all the allocators are empty.
|
||||
If you don't pass a pointer to a bool, then will raise an error all the allocators are
|
||||
not empty.
|
||||
*/
|
||||
void debug_check_empty(bool* result = nullptr)
|
||||
{
|
||||
#ifndef USE_MALLOC
|
||||
// This is a debugging function. It checks that all memory from all
|
||||
// allocators has been freed.
|
||||
size_t alloc_count = 0;
|
||||
|
||||
auto* alloc = Parent::iterate();
|
||||
|
||||
// Count the linked allocators.
|
||||
while (alloc != nullptr)
|
||||
{
|
||||
alloc = Parent::iterate(alloc);
|
||||
alloc_count++;
|
||||
}
|
||||
|
||||
bool done = false;
|
||||
|
||||
size_t non_empty_count = 0;
|
||||
while (!done)
|
||||
{
|
||||
done = true;
|
||||
alloc = Parent::iterate();
|
||||
non_empty_count = 0;
|
||||
|
||||
while (alloc != nullptr)
|
||||
{
|
||||
// Destroy the message queue so that it has no stub message.
|
||||
Remote* p = alloc->message_queue().destroy();
|
||||
|
||||
while (p != nullptr)
|
||||
while (p != nullptr)
|
||||
{
|
||||
Remote* next = p->non_atomic_next;
|
||||
alloc->handle_dealloc_remote(p);
|
||||
p = next;
|
||||
}
|
||||
|
||||
// Check that the allocator has freed all memory.
|
||||
if (!alloc->stats().is_empty())
|
||||
non_empty_count++;
|
||||
|
||||
// Place the static stub message on the queue.
|
||||
alloc->init_message_queue();
|
||||
|
||||
@@ -158,20 +160,16 @@ namespace snmalloc
|
||||
}
|
||||
}
|
||||
|
||||
alloc = Parent::iterate();
|
||||
size_t empty_count = 0;
|
||||
|
||||
while (alloc != nullptr)
|
||||
if (result != nullptr)
|
||||
{
|
||||
// Check that the allocator has freed all memory.
|
||||
if (alloc->stats().is_empty())
|
||||
empty_count++;
|
||||
|
||||
alloc = Parent::iterate(alloc);
|
||||
*result = non_empty_count == 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (alloc_count != empty_count)
|
||||
error("Incorrect number of allocators");
|
||||
if (non_empty_count != 0)
|
||||
{
|
||||
error("debug_check_empty: found non-empty allocators");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user