[+] o1heapTraverseHeap

This commit is contained in:
Reece Wilson 2024-03-04 04:19:47 +00:00
parent 8f982a15d5
commit 299c082b73
2 changed files with 25 additions and 0 deletions

View File

@ -462,6 +462,28 @@ void o1heapFree(O1HeapInstance *const handle, void *const pointer)
}
}
void o1heapTraverseHeap(const O1HeapInstance *const handle, bool(*fCallback)(void *, void *), void *pSecondArg)
{
AU_LOCK_GUARD(handle->mutex);
Fragment *const frag = (Fragment *)(void *)(((uint8_t *)handle) + INSTANCE_SIZE_PADDED);
O1HEAP_ASSERT((((size_t)frag) % O1HEAP_ALIGNMENT) == 0U);
const Fragment *curFrag = frag;
do
{
if (curFrag->header.used)
{
if (!fCallback(((uint8_t *)curFrag) + O1HEAP_ALIGNMENT, pSecondArg))
{
break;
}
}
}
while (curFrag = curFrag->header.next);
}
bool o1heapDoInvariantsHold(const O1HeapInstance *const handle)
{
O1HEAP_ASSERT(handle != NULL);

View File

@ -146,3 +146,6 @@ bool o1heapDoInvariantsHold(const O1HeapInstance *const handle);
/// If the handle pointer is NULL, the behavior is undefined.
O1HeapDiagnostics o1heapGetDiagnostics(const O1HeapInstance *const handle);
///
///
void o1heapTraverseHeap(const O1HeapInstance *const handle, bool(*fCallback)(void *, void *), void *pSecondArg);