From 7ffd1d5e5b41393b518ad0a3b6e94056d9044e26 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 28 Aug 2008 15:10:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@413 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chheap.c | 26 ++++++++++++++++++++++++-- src/chinit.c | 6 ++++++ src/include/heap.h | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/chheap.c b/src/chheap.c index dbab1dbd5..0cda7f268 100644 --- a/src/chheap.c +++ b/src/chheap.c @@ -49,7 +49,7 @@ static struct { Mutex hmtx; #elif defined(CH_USE_SEMAPHORES) #define H_LOCK() chSemWait(&heap.hsem) -#define H_UNLOCK() chMtxSignal(&heap.hsem) +#define H_UNLOCK() chSemSignal(&heap.hsem) Semaphore hsem; #else #error "The heap allocator requires mutexes or semaphores to be enabled" @@ -181,6 +181,23 @@ void chHeapFree(void *p) { } } +/** + * Checks if the heap is non-empty and non-fragmented. + * @return \p TRUE if the condition is satisfied + * @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; + + H_LOCK(); + + b = (heap.free.h_next != NULL) && (heap.free.h_next->h_next == NULL); + + H_UNLOCK(); + return b; +} + #else /* CH_USE_MALLOC_HEAP */ #include @@ -191,7 +208,7 @@ void chHeapFree(void *p) { static Mutex hmtx; #elif defined(CH_USE_SEMAPHORES) #define H_LOCK() chSemWait(&hsem) -#define H_UNLOCK() chMtxSignal(&hsem) +#define H_UNLOCK() chSemSignal(&hsem) static Semaphore hsem; #else #error "The heap allocator requires mutexes or semaphores to be enabled" @@ -226,6 +243,11 @@ void chHeapFree(void *p) { H_UNLOCK(); } +bool_t chHeapNotFragmented(void) { + + return FALSE; +} + #endif /* CH_USE_MALLOC_HEAP */ #endif /* CH_USE_HEAP */ diff --git a/src/chinit.c b/src/chinit.c index 243ef2a97..5e6788693 100644 --- a/src/chinit.c +++ b/src/chinit.c @@ -39,6 +39,12 @@ void chSysInit(void) { chDbgInit(); #ifdef CH_USE_VIRTUAL_TIMERS chVTInit(); +#endif +#ifdef CH_USE_HEAP + chHeapInit(); +#endif +#ifdef CH_USE_HEAP + chHeapInit(); #endif /* * Now this instructions flow becomes the main thread. diff --git a/src/include/heap.h b/src/include/heap.h index 9619eba2f..d1aa83903 100644 --- a/src/include/heap.h +++ b/src/include/heap.h @@ -31,6 +31,7 @@ extern "C" { void chHeapInit(void); void *chHeapAlloc(size_t size); void chHeapFree(void *p); + bool_t chHeapNotFragmented(void); #ifdef __cplusplus } #endif -- cgit v1.2.3