From 9e05eaaf91c2596521e29b90ffa9adf3114c3b93 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 28 Jan 2011 20:11:32 +0100 Subject: Proper mutex usage, and protecting malloc and sbrk using them. Also showing this into the demo. --- os/src/malloc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'os/src/malloc.c') 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 #include +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); } -- cgit v1.2.3