From 79bedccb6c48dfadc47ac91549ba0043d3ab9e53 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 29 Aug 2008 17:31:01 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@416 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chheap.c | 30 ++++++++++++++++++++++-------- src/include/heap.h | 2 +- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/chheap.c b/src/chheap.c index faa3cc42f..3069d5be6 100644 --- a/src/chheap.c +++ b/src/chheap.c @@ -184,20 +184,32 @@ void chHeapFree(void *p) { } /** - * Checks if the heap is non-empty and non-fragmented. - * @return \p TRUE if the condition is satisfied + * Determines the heap status. + * @sizep pointer to a variable that will receive the total fragmented free + * space + * @return the number of fragments in the heap * @note This function is meant to be used in the test suite, it should not be * really useful for the application code. */ -bool_t chHeapNotFragmented(void) { - bool_t b; +size_t chHeapStatus(size_t *sizep) { + struct header *qp; + size_t n, sz; H_LOCK(); - b = (heap.free.h_next != NULL) && (heap.free.h_next->h_next == NULL); + sz = 0; + for (n = 0, qp = &heap.free; qp->h_next; n++, qp = qp->h_next) + sz += qp->h_next->h_size; + if (sizep) + *sizep = sz; + +// if ((heap.free.h_next != NULL) && (heap.free.h_next->h_next == NULL)) +// n = heap.free.h_next->h_size; +// else +// n = 0; H_UNLOCK(); - return b; + return n; } #else /* CH_USE_MALLOC_HEAP */ @@ -245,9 +257,11 @@ void chHeapFree(void *p) { H_UNLOCK(); } -bool_t chHeapNotFragmented(void) { +size_t chHeapStatus(size_t *sizep) { - return FALSE; + if (sizep) + *sizep = 0; + return 0; } #endif /* CH_USE_MALLOC_HEAP */ diff --git a/src/include/heap.h b/src/include/heap.h index d1aa83903..b303fde1a 100644 --- a/src/include/heap.h +++ b/src/include/heap.h @@ -31,7 +31,7 @@ extern "C" { void chHeapInit(void); void *chHeapAlloc(size_t size); void chHeapFree(void *p); - bool_t chHeapNotFragmented(void); + size_t chHeapStatus(size_t *sizep); #ifdef __cplusplus } #endif -- cgit v1.2.3