From 299c082b733d2b2fbcae8eed6b9e284b3ddd85f9 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Mon, 4 Mar 2024 04:19:47 +0000 Subject: [PATCH] [+] o1heapTraverseHeap --- o1heap.cpp | 22 ++++++++++++++++++++++ o1heap.hpp | 3 +++ 2 files changed, 25 insertions(+) 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