summaryrefslogtreecommitdiff
path: root/os/src/malloc.c
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2011-01-28 20:11:32 +0100
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2011-01-28 20:11:32 +0100
commit9e05eaaf91c2596521e29b90ffa9adf3114c3b93 (patch)
tree150d5d7fdbb6d9fbb93a4c1277a8132e1e423a07 /os/src/malloc.c
parenta0f170eb2100291429d31a057977a88ece219519 (diff)
Proper mutex usage, and protecting malloc and sbrk using them. Also showing this into the demo.
Diffstat (limited to 'os/src/malloc.c')
-rw-r--r--os/src/malloc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/os/src/malloc.c b/os/src/malloc.c
index 0906cc0..a24a87f 100644
--- a/os/src/malloc.c
+++ b/os/src/malloc.c
@@ -2,7 +2,18 @@
#include <malloc.h>
#include <osdebug.h>
+static xSemaphoreHandle malloc_sem = NULL;
+
+__attribute__((constructor)) static void malloc_init() {
+ malloc_sem = xSemaphoreCreateMutex();
+}
+
void * malloc(size_t size) {
- DBGOUT("malloc(%u)\r\n", size);
- return _malloc_r(_impure_ptr, size);
+ void * ptr;
+
+ if (malloc_sem)
+ xSemaphoreTake(malloc_sem, portMAX_DELAY);
+ ptr =_malloc_r(_impure_ptr, size);
+ if (malloc_sem)
+ xSemaphoreGive(malloc_sem);
}