-
Notifications
You must be signed in to change notification settings - Fork 14
/
tlsf.h
58 lines (48 loc) · 1.16 KB
/
tlsf.h
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
/*
* SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once
/* Inhibit C++ name-mangling for tlsf functions */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stddef.h>
#include <stdint.h>
#define _TLSF_SL_COUNT 16
#if __SIZE_WIDTH__ == 64
#define _TLSF_FL_COUNT 32
#define _TLSF_FL_MAX 38
#else
#define _TLSF_FL_COUNT 25
#define _TLSF_FL_MAX 30
#endif
#define TLSF_MAX_SIZE (((size_t) 1 << (_TLSF_FL_MAX - 1)) - sizeof(size_t))
#define TLSF_INIT ((tlsf_t){.size = 0})
typedef struct {
uint32_t fl, sl[_TLSF_FL_COUNT];
struct tlsf_block *block[_TLSF_FL_COUNT][_TLSF_SL_COUNT];
size_t size;
} tlsf_t;
void *tlsf_resize(tlsf_t *, size_t);
void *tlsf_aalloc(tlsf_t *, size_t, size_t);
/**
* Allocates the requested @size bytes of memory and returns a pointer to it.
* On failure, returns NULL.
*/
void *tlsf_malloc(tlsf_t *, size_t size);
void *tlsf_realloc(tlsf_t *, void *, size_t);
/**
* Releases the previously allocated memory, given the pointer.
*/
void tlsf_free(tlsf_t *, void *);
#ifdef TLSF_ENABLE_CHECK
void tlsf_check(tlsf_t *);
#else
static inline void tlsf_check(tlsf_t *t)
{
(void) t;
}
#endif
#ifdef __cplusplus
}
#endif