1 /* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric BAIL
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.
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.
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/>.
25 #include <ememoa_mempool_fixed.h>
27 #include "eina_inlist.h"
28 #include "eina_error.h"
29 #include "eina_module.h"
30 #include "eina_mempool.h"
32 #include "eina_private.h"
34 typedef struct _Eina_Ememoa_Fixed_Mempool Eina_Ememoa_Fixed_Mempool;
35 struct _Eina_Ememoa_Fixed_Mempool
37 struct ememoa_mempool_desc_s *desc;
42 eina_ememoa_fixed_malloc(void *data, __UNUSED__ unsigned int size)
44 Eina_Ememoa_Fixed_Mempool *efm = data;
46 return ememoa_mempool_fixed_pop_object(efm->pool);
50 eina_ememoa_fixed_free(void *data, void *ptr)
52 Eina_Ememoa_Fixed_Mempool *efm = data;
54 ememoa_mempool_fixed_push_object(efm->pool, ptr);
58 eina_ememoa_fixed_realloc(__UNUSED__ void *data,
59 __UNUSED__ void *element,
60 __UNUSED__ unsigned int size)
66 eina_ememoa_fixed_gc(void *data)
68 Eina_Ememoa_Fixed_Mempool *efm = data;
70 ememoa_mempool_fixed_garbage_collect(efm->pool);
74 eina_ememoa_fixed_statistics(void *data)
76 Eina_Ememoa_Fixed_Mempool *efm = data;
78 ememoa_mempool_fixed_display_statistic(efm->pool);
83 eina_ememoa_fixed_init(const char *context,
84 __UNUSED__ const char *option,
87 struct ememoa_mempool_desc_s *desc = NULL;
88 Eina_Ememoa_Fixed_Mempool *efm = NULL;
89 Eina_Bool thread_protect;
96 context_length = strlen(context) + 1;
98 desc = calloc(1, sizeof (struct ememoa_mempool_desc_s) + context_length);
102 desc->name = (char *)(desc + 1);
103 memcpy((char *)desc->name, context, context_length);
106 item_size = va_arg(args, int);
107 pool_size = va_arg(args, int);
108 thread_protect = va_arg(args, int);
110 efm = malloc(sizeof (Eina_Ememoa_Fixed_Mempool));
115 efm->pool = ememoa_mempool_fixed_init(
119 EMEMOA_THREAD_PROTECTION : 0,
137 eina_ememoa_fixed_shutdown(void *data)
139 Eina_Ememoa_Fixed_Mempool *efm = data;
144 ememoa_mempool_fixed_clean(efm->pool);
148 static Eina_Mempool_Backend _eina_ememoa_mp_backend = {
149 .name = "ememoa_fixed",
150 .init = &eina_ememoa_fixed_init,
151 .shutdown = &eina_ememoa_fixed_shutdown,
152 .realloc = &eina_ememoa_fixed_realloc,
153 .alloc = &eina_ememoa_fixed_malloc,
154 .free = &eina_ememoa_fixed_free,
155 .garbage_collect = &eina_ememoa_fixed_gc,
156 .statistics = &eina_ememoa_fixed_statistics,
160 Eina_Bool ememoa_fixed_init(void)
162 return eina_mempool_register(&_eina_ememoa_mp_backend);
165 void ememoa_fixed_shutdown(void)
167 eina_mempool_unregister(&_eina_ememoa_mp_backend);
171 #ifndef EINA_STATIC_BUILD_EMEMOA_FIXED
173 EINA_MODULE_INIT(ememoa_fixed_init);
174 EINA_MODULE_SHUTDOWN(ememoa_fixed_shutdown);
176 #endif /* ! EINA_STATIC_BUILD_EMEMOA_FIXED */