diff --git a/o1heap.cpp b/o1heap.cpp index 043d3b0..715910d 100644 --- a/o1heap.cpp +++ b/o1heap.cpp @@ -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); diff --git a/o1heap.hpp b/o1heap.hpp index b6210e2..f8f8aeb 100644 --- a/o1heap.hpp +++ b/o1heap.hpp @@ -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); \ No newline at end of file