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