aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-08-28 15:10:54 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-08-28 15:10:54 +0000
commit7ffd1d5e5b41393b518ad0a3b6e94056d9044e26 (patch)
tree90e9f89b83930f4c6331443d44d663642c20284d /src
parent7768c51b7b1ef0becc4090705a9bd2f14aa28d00 (diff)
downloadChibiOS-7ffd1d5e5b41393b518ad0a3b6e94056d9044e26.tar.gz
ChibiOS-7ffd1d5e5b41393b518ad0a3b6e94056d9044e26.tar.bz2
ChibiOS-7ffd1d5e5b41393b518ad0a3b6e94056d9044e26.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@413 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
-rw-r--r--src/chheap.c26
-rw-r--r--src/chinit.c6
-rw-r--r--src/include/heap.h1
3 files changed, 31 insertions, 2 deletions
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 <stdlib.h>
@@ -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
@@ -40,6 +40,12 @@ void chSysInit(void) {
#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