-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathtlsf-malloc.c
62 lines (54 loc) · 1.3 KB
/
tlsf-malloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright (C) 2014-2018 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup pkg_tlsf_malloc
* @ingroup pkg
* @ingroup sys
* @{
* @file
*
* @brief TLSF-based global memory allocator.
* @author Juan I Carrano
*
*/
#include <stdio.h>
#include "tlsf.h"
#include "tlsf-malloc.h"
#include "tlsf-malloc-internal.h"
/**
* Global memory heap (really a collection of pools, or areas)
**/
tlsf_t tlsf_malloc_gheap = NULL;
int tlsf_add_global_pool(void *mem, size_t bytes)
{
if (tlsf_malloc_gheap == NULL) {
tlsf_malloc_gheap = tlsf_create_with_pool(mem, bytes);
return tlsf_malloc_gheap == NULL;
}
else {
return tlsf_add_pool(tlsf_malloc_gheap, mem, bytes) == NULL;
}
}
tlsf_t _tlsf_get_global_control(void)
{
return tlsf_malloc_gheap;
}
void tlsf_size_walker(void* ptr, size_t size, int used, void* user)
{
printf("\t%p %s size: %" PRIuSIZE " (%p)\n", ptr, used ? "used" : "free",
size, ptr);
if (used) {
((tlsf_size_container_t *)user)->used += (unsigned int)size;
}
else {
((tlsf_size_container_t *)user)->free += (unsigned int)size;
}
}
/**
* @}
*/