blob: 281a75be1a2642f097735b655a2cee23b134552b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <reent.h>
#include <malloc.h>
#include <FreeRTOS.h>
#include <semphr.h>
static xSemaphoreHandle malloc_sem = NULL;
__attribute__((constructor)) static void malloc_init() {
malloc_sem = xSemaphoreCreateMutex();
}
void * malloc(size_t size) {
void * ptr;
if (malloc_sem)
xSemaphoreTake(malloc_sem, portMAX_DELAY);
ptr =_malloc_r(_impure_ptr, size);
if (malloc_sem)
xSemaphoreGive(malloc_sem);
return ptr;
}
|