diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c')
-rw-r--r-- | libraries/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/libraries/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c b/libraries/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c new file mode 100644 index 0000000..56b99f6 --- /dev/null +++ b/libraries/eina/src/modules/mp/ememoa_unknown/eina_ememoa_unknown.c | |||
@@ -0,0 +1,182 @@ | |||
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 | #ifdef HAVE_CONFIG_H | ||
20 | # include "config.h" | ||
21 | #endif | ||
22 | |||
23 | #include <stdlib.h> | ||
24 | #include <string.h> | ||
25 | #include <ememoa_mempool_fixed.h> | ||
26 | #include <ememoa_mempool_unknown_size.h> | ||
27 | |||
28 | #include "eina_types.h" | ||
29 | #include "eina_module.h" | ||
30 | #include "eina_private.h" | ||
31 | #include "eina_mempool.h" | ||
32 | |||
33 | typedef struct _Eina_Ememoa_Unknown_Size_Mempool | ||
34 | Eina_Ememoa_Unknown_Size_Mempool; | ||
35 | struct _Eina_Ememoa_Unknown_Size_Mempool | ||
36 | { | ||
37 | struct ememoa_mempool_desc_s *desc; | ||
38 | int pool; | ||
39 | }; | ||
40 | |||
41 | static void * | ||
42 | eina_ememoa_unknown_size_malloc(void *data, unsigned int size) | ||
43 | { | ||
44 | Eina_Ememoa_Unknown_Size_Mempool *efm = data; | ||
45 | |||
46 | return ememoa_mempool_unknown_size_pop_object(efm->pool, size); | ||
47 | } | ||
48 | |||
49 | static void | ||
50 | eina_ememoa_unknown_size_free(void *data, void *ptr) | ||
51 | { | ||
52 | Eina_Ememoa_Unknown_Size_Mempool *efm = data; | ||
53 | |||
54 | ememoa_mempool_unknown_size_push_object(efm->pool, ptr); | ||
55 | } | ||
56 | |||
57 | static void * | ||
58 | eina_ememoa_unknown_size_realloc(void *data, void *element, unsigned int size) | ||
59 | { | ||
60 | Eina_Ememoa_Unknown_Size_Mempool *efm = data; | ||
61 | |||
62 | return ememoa_mempool_unknown_size_resize_object(efm->pool, element, size); | ||
63 | } | ||
64 | |||
65 | static void | ||
66 | eina_ememoa_unknown_size_gc(void *data) | ||
67 | { | ||
68 | Eina_Ememoa_Unknown_Size_Mempool *efm = data; | ||
69 | |||
70 | ememoa_mempool_unknown_size_garbage_collect(efm->pool); | ||
71 | } | ||
72 | |||
73 | static void | ||
74 | eina_ememoa_unknown_size_statistics(void *data) | ||
75 | { | ||
76 | Eina_Ememoa_Unknown_Size_Mempool *efm = data; | ||
77 | |||
78 | ememoa_mempool_unknown_size_display_statistic(efm->pool); | ||
79 | } | ||
80 | |||
81 | static void * | ||
82 | eina_ememoa_unknown_size_init(const char *context, | ||
83 | __UNUSED__ const char *option, | ||
84 | va_list args) | ||
85 | { | ||
86 | struct ememoa_mempool_desc_s *desc = NULL; | ||
87 | Eina_Ememoa_Unknown_Size_Mempool *efm = NULL; | ||
88 | Eina_Bool thread_protect; | ||
89 | unsigned int *items_map = NULL; | ||
90 | unsigned int items_count; | ||
91 | unsigned int i; | ||
92 | int context_length; | ||
93 | |||
94 | if (context) | ||
95 | { | ||
96 | context_length = strlen(context) + 1; | ||
97 | |||
98 | desc = calloc(1, sizeof (struct ememoa_mempool_desc_s) + context_length); | ||
99 | if (!desc) | ||
100 | goto on_error; | ||
101 | |||
102 | desc->name = (char *)(desc + 1); | ||
103 | memcpy((char *)desc->name, context, context_length); | ||
104 | } | ||
105 | |||
106 | thread_protect = va_arg(args, int); | ||
107 | items_count = va_arg(args, unsigned int); | ||
108 | |||
109 | items_map = malloc(sizeof (unsigned int) * 2 * items_count); | ||
110 | |||
111 | for (i = 0; i < (items_count << 1); ++i) | ||
112 | items_map[i] = va_arg(args, unsigned int); | ||
113 | |||
114 | efm = malloc(sizeof (Eina_Ememoa_Unknown_Size_Mempool)); | ||
115 | if (!efm) | ||
116 | goto on_error; | ||
117 | |||
118 | efm->desc = desc; | ||
119 | efm->pool = ememoa_mempool_unknown_size_init( | ||
120 | items_count, | ||
121 | items_map, | ||
122 | thread_protect ? | ||
123 | EMEMOA_THREAD_PROTECTION : 0, | ||
124 | efm->desc); | ||
125 | if (efm->pool < 0) | ||
126 | goto on_error; | ||
127 | |||
128 | return efm; | ||
129 | |||
130 | on_error: | ||
131 | if (items_map) | ||
132 | free(items_map); | ||
133 | |||
134 | if (desc) | ||
135 | free(desc); | ||
136 | |||
137 | if (efm) | ||
138 | free(efm); | ||
139 | |||
140 | return NULL; | ||
141 | } | ||
142 | |||
143 | static void | ||
144 | eina_ememoa_unknown_size_shutdown(void *data) | ||
145 | { | ||
146 | Eina_Ememoa_Unknown_Size_Mempool *efm = data; | ||
147 | |||
148 | if (efm->desc) | ||
149 | free(efm->desc); | ||
150 | |||
151 | ememoa_mempool_unknown_size_clean(efm->pool); | ||
152 | free(efm); | ||
153 | } | ||
154 | |||
155 | static Eina_Mempool_Backend _eina_ememoa_unknown_mp_backend = { | ||
156 | .name = "ememoa_unknown", | ||
157 | .init = &eina_ememoa_unknown_size_init, | ||
158 | .shutdown = &eina_ememoa_unknown_size_shutdown, | ||
159 | .realloc = &eina_ememoa_unknown_size_realloc, | ||
160 | .alloc = &eina_ememoa_unknown_size_malloc, | ||
161 | .free = &eina_ememoa_unknown_size_free, | ||
162 | .garbage_collect = &eina_ememoa_unknown_size_gc, | ||
163 | .statistics = &eina_ememoa_unknown_size_statistics, | ||
164 | .repack = NULL | ||
165 | }; | ||
166 | |||
167 | Eina_Bool ememoa_unknown_init(void) | ||
168 | { | ||
169 | return eina_mempool_register(&_eina_ememoa_unknown_mp_backend); | ||
170 | } | ||
171 | |||
172 | void ememoa_unknown_shutdown(void) | ||
173 | { | ||
174 | eina_mempool_unregister(&_eina_ememoa_unknown_mp_backend); | ||
175 | } | ||
176 | |||
177 | #ifndef EINA_STATIC_BUILD_EMEMOA_UNKNOWN | ||
178 | |||
179 | EINA_MODULE_INIT(ememoa_unknown_init); | ||
180 | EINA_MODULE_SHUTDOWN(ememoa_unknown_shutdown); | ||
181 | |||
182 | #endif /* ! EINA_STATIC_BUILD_EMEMOA_UNKNOWN */ | ||