uc-sdk
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
malloc_wrapper.c
Go to the documentation of this file.
1
#include <
malloc.h
>
2
#include <
FreeRTOS.h
>
3
#include <
semphr.h
>
4
5
static
xSemaphoreHandle
malloc_sem =
NULL
;
6
static
malloc_t
old_malloc;
7
static
realloc_t
old_realloc;
8
static
free_t
old_free;
9
10
static
void
* malloc_wrap(
size_t
s) {
11
void
* r;
12
xSemaphoreTakeRecursive
(malloc_sem,
portMAX_DELAY
);
13
r = old_malloc(s);
14
xSemaphoreGiveRecursive
(malloc_sem);
15
return
r;
16
}
17
18
static
void
* realloc_wrap(
void
* p,
size_t
s) {
19
void
* r;
20
xSemaphoreTakeRecursive
(malloc_sem,
portMAX_DELAY
);
21
r = old_realloc(p, s);
22
xSemaphoreGiveRecursive
(malloc_sem);
23
return
r;
24
}
25
26
static
void
free_wrap(
void
* p) {
27
xSemaphoreTakeRecursive
(malloc_sem,
portMAX_DELAY
);
28
old_free(p);
29
xSemaphoreGiveRecursive
(malloc_sem);
30
}
31
32
void
init_malloc_wrapper
() {
33
malloc_sem =
xSemaphoreCreateRecursiveMutex
();
34
old_malloc =
malloc
;
35
old_realloc =
realloc
;
36
old_free =
free
;
37
malloc
= malloc_wrap;
38
realloc
= realloc_wrap;
39
free
= free_wrap;
40
}
41
acorn
src
malloc_wrapper.c
Generated on Fri Nov 15 2013 05:00:15 for uc-sdk by
1.8.4