diff options
Diffstat (limited to 'libraries/eina/src/include/eina_inline_mempool.x')
-rw-r--r-- | libraries/eina/src/include/eina_inline_mempool.x | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_inline_mempool.x b/libraries/eina/src/include/eina_inline_mempool.x new file mode 100644 index 0000000..a67ec3d --- /dev/null +++ b/libraries/eina/src/include/eina_inline_mempool.x | |||
@@ -0,0 +1,127 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2008 Cedric Bail | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifndef EINA_INLINE_MEMPOOL_X_ | ||
20 | #define EINA_INLINE_MEMPOOL_X_ | ||
21 | |||
22 | /** | ||
23 | * @addtogroup Eina_Memory_Pool_Group Memory Pool | ||
24 | * | ||
25 | * @{ | ||
26 | */ | ||
27 | |||
28 | /* Memory Pool */ | ||
29 | typedef struct _Eina_Mempool_Backend_ABI1 Eina_Mempool_Backend_ABI1; | ||
30 | typedef struct _Eina_Mempool_Backend_ABI2 Eina_Mempool_Backend_ABI2; | ||
31 | |||
32 | struct _Eina_Mempool_Backend | ||
33 | { | ||
34 | const char *name; | ||
35 | void *(*init)(const char *context, const char *options, va_list args); | ||
36 | void (*free)(void *data, void *element); | ||
37 | void *(*alloc)(void *data, unsigned int size); | ||
38 | void *(*realloc)(void *data, void *element, unsigned int size); | ||
39 | void (*garbage_collect)(void *data); | ||
40 | void (*statistics)(void *data); | ||
41 | void (*shutdown)(void *data); | ||
42 | void (*repack)(void *data, Eina_Mempool_Repack_Cb cb, void *cb_data); | ||
43 | }; | ||
44 | |||
45 | struct _Eina_Mempool_Backend_ABI1 | ||
46 | { | ||
47 | const char *name; | ||
48 | void *(*init)(const char *context, const char *options, va_list args); | ||
49 | void (*free)(void *data, void *element); | ||
50 | void *(*alloc)(void *data, unsigned int size); | ||
51 | void *(*realloc)(void *data, void *element, unsigned int size); | ||
52 | void (*garbage_collect)(void *data); | ||
53 | void (*statistics)(void *data); | ||
54 | void (*shutdown)(void *data); | ||
55 | }; | ||
56 | |||
57 | struct _Eina_Mempool_Backend_ABI2 | ||
58 | { | ||
59 | void (*repack)(void *data, Eina_Mempool_Repack_Cb cb, void *cb_data); | ||
60 | }; | ||
61 | |||
62 | struct _Eina_Mempool | ||
63 | { | ||
64 | Eina_Mempool_Backend_ABI1 backend; | ||
65 | void *backend_data; | ||
66 | Eina_Mempool_Backend_ABI2 *backend2; | ||
67 | }; | ||
68 | |||
69 | /** | ||
70 | * @brief Re-allocate a amount memory by the given mempool. | ||
71 | * | ||
72 | * @param mp The mempool. | ||
73 | * @param element The element to re-allocate. | ||
74 | * @param size The size in bytes to re-allocate. | ||
75 | * @return The newly re-allocated data. | ||
76 | * | ||
77 | * This function re-allocates @p element with @p size bytes, using the | ||
78 | * mempool @p mp and returns the allocated data. If not used anymore, | ||
79 | * the data must be freed with eina_mempool_free(). No check is done | ||
80 | * on @p mp, so it must be a valid mempool. | ||
81 | */ | ||
82 | static inline void * | ||
83 | eina_mempool_realloc(Eina_Mempool *mp, void *element, unsigned int size) | ||
84 | { | ||
85 | return mp->backend.realloc(mp->backend_data, element, size); | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * @brief Allocate a amount memory by the given mempool. | ||
90 | * | ||
91 | * @param mp The mempool. | ||
92 | * @param size The size in bytes to allocate. | ||
93 | * @return The newly allocated data. | ||
94 | * | ||
95 | * This function allocates @p size bytes, using the mempool @p mp and | ||
96 | * returns the allocated data. If not used anymore, the data must be | ||
97 | * freed with eina_mempool_free(). No check is done on @p mp, so it | ||
98 | * must be a valid mempool. | ||
99 | */ | ||
100 | static inline void * | ||
101 | eina_mempool_malloc(Eina_Mempool *mp, unsigned int size) | ||
102 | { | ||
103 | return mp->backend.alloc(mp->backend_data, size); | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * @brief Free the allocated ressources by the given mempool. | ||
108 | * | ||
109 | * @param mp The mempool. | ||
110 | * @param element The data to free. | ||
111 | * | ||
112 | * This function frees @p element allocated by @p mp. @p element must | ||
113 | * have been obtained by eina_mempool_malloc() or | ||
114 | * eina_mempool_realloc(). No check is done on @p mp, so it must be a | ||
115 | * valid mempool. | ||
116 | */ | ||
117 | static inline void | ||
118 | eina_mempool_free(Eina_Mempool *mp, void *element) | ||
119 | { | ||
120 | mp->backend.free(mp->backend_data, element); | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * @} | ||
125 | */ | ||
126 | |||
127 | #endif | ||