diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2011-01-28 20:11:32 +0100 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2011-01-28 20:11:32 +0100 |
commit | 9e05eaaf91c2596521e29b90ffa9adf3114c3b93 (patch) | |
tree | 150d5d7fdbb6d9fbb93a4c1277a8132e1e423a07 /os/src/sbrk.c | |
parent | a0f170eb2100291429d31a057977a88ece219519 (diff) |
Proper mutex usage, and protecting malloc and sbrk using them. Also showing this into the demo.
Diffstat (limited to 'os/src/sbrk.c')
-rw-r--r-- | os/src/sbrk.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/os/src/sbrk.c b/os/src/sbrk.c index df196f0..ac8649c 100644 --- a/os/src/sbrk.c +++ b/os/src/sbrk.c @@ -17,25 +17,19 @@ extern uintptr_t __stack_start; /* Low-level bulk RAM allocator -- used by Newlib's Malloc */ static void *heap_end = (void *) &__heap_start; -#define USE_SBRK_MUTEX 0 - -#if USE_SBRK_MUTEX -static xSemaphoreHandle sbrk_sem; +static xSemaphoreHandle sbrk_sem = NULL; __attribute__((constructor)) static void sbrk_init() { - DBGOUT("Creating Mutex..."); sbrk_sem = xSemaphoreCreateMutex(); } -#endif void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) { void *prev_heap_end, *next_heap_end, *ret; void *stack_min = (void *) &__stack_start; - -#if USE_SBRK_MUTEX - xSemaphoreTake(sbrk_sem, portMAX_DELAY); -#endif + + if (sbrk_sem) + xSemaphoreTake(sbrk_sem, portMAX_DELAY); prev_heap_end = heap_end; @@ -51,9 +45,8 @@ void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) ret = (void *)prev_heap_end; } -#if USE_SBRK_MUTEX - xSemaphoreGive(sbrk_sem); -#endif + if (sbrk_sem) + xSemaphoreGive(sbrk_sem); return ret; } |