diff options
author | Gustavo Sverzut Barbieri <barbieri@gmail.com> | 2012-10-10 19:57:53 +0000 |
---|---|---|
committer | Gustavo Sverzut Barbieri <barbieri@gmail.com> | 2012-10-10 19:57:53 +0000 |
commit | 4d35e4ca03005d2f7fcf75caa877deb804d2f48a (patch) | |
tree | 111aebc08432286f540329e39aa84fd379e23b33 /src | |
parent | 59ed22a467fb4918064e5fa9dc6c75bee37faeaf (diff) |
efl: simplify mempools, nuke some and make remaining statically built.
Now we always build the following memory pools statically:
- pass_through: calls malloc/free directly, useful to debug.
- chained_pool: default for ages.
- one_big: used by some embedded systems (should we remove?)
Removed:
- ememoa_fixed and ememoa_unknown: depends on a separate lib, not supported?
- buddy: nobody uses it?
NOTE: we do not need the src/modules/eina/mp/*/Makefile.am anymore
since they are statically built. But I'll keep these and the
references in src/modules/eina/mp/Makefile.am
SVN revision: 77792
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/eina/Makefile.am | 16 | ||||
-rw-r--r-- | src/lib/eina/eina_mempool.c | 44 | ||||
-rw-r--r-- | src/lib/eina/eina_mempool.h | 14 | ||||
-rw-r--r-- | src/modules/eina/mp/Makefile.am | 24 | ||||
-rw-r--r-- | src/modules/eina/mp/buddy/Makefile.am | 27 | ||||
-rw-r--r-- | src/modules/eina/mp/buddy/eina_buddy.c | 292 | ||||
-rw-r--r-- | src/modules/eina/mp/ememoa_fixed/Makefile.am | 28 | ||||
-rw-r--r-- | src/modules/eina/mp/ememoa_fixed/eina_ememoa_fixed.c | 176 | ||||
-rw-r--r-- | src/modules/eina/mp/ememoa_unknown/Makefile.am | 28 | ||||
-rw-r--r-- | src/modules/eina/mp/ememoa_unknown/eina_ememoa_unknown.c | 182 | ||||
-rw-r--r-- | src/modules/eina/mp/fixed_bitmap/Makefile.am | 27 | ||||
-rw-r--r-- | src/modules/eina/mp/fixed_bitmap/eina_fixed_bitmap.c | 270 |
12 files changed, 0 insertions, 1128 deletions
diff --git a/src/lib/eina/Makefile.am b/src/lib/eina/Makefile.am index c80a38937d..0797f89d72 100644 --- a/src/lib/eina/Makefile.am +++ b/src/lib/eina/Makefile.am | |||
@@ -173,26 +173,10 @@ eina_binbuf_template_c.x | |||
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
176 | if EINA_STATIC_BUILD_BUDDY | ||
177 | libeina_la_SOURCES += $(top_srcdir)/src/modules/eina/mp/buddy/eina_buddy.c | ||
178 | endif | ||
179 | |||
180 | if EINA_STATIC_BUILD_CHAINED_POOL | 176 | if EINA_STATIC_BUILD_CHAINED_POOL |
181 | libeina_la_SOURCES += $(top_srcdir)/src/modules/eina/mp/chained_pool/eina_chained_mempool.c | 177 | libeina_la_SOURCES += $(top_srcdir)/src/modules/eina/mp/chained_pool/eina_chained_mempool.c |
182 | endif | 178 | endif |
183 | 179 | ||
184 | if EINA_STATIC_BUILD_EMEMOA_FIXED | ||
185 | libeina_la_SOURCES += $(top_srcdir)/src/modules/eina/mp/ememoa_fixed/eina_ememoa_fixed.c | ||
186 | endif | ||
187 | |||
188 | if EINA_STATIC_BUILD_EMEMOA_UNKNOWN | ||
189 | libeina_la_SOURCES += $(top_srcdir)/src/modules/eina/mp/ememoa_unknown/eina_ememoa_unknown.c | ||
190 | endif | ||
191 | |||
192 | if EINA_STATIC_BUILD_FIXED_BITMAP | ||
193 | libeina_la_SOURCES += $(top_srcdir)/src/modules/eina/mp/fixed_bitmap/eina_fixed_bitmap.c | ||
194 | endif | ||
195 | |||
196 | if EINA_STATIC_BUILD_ONE_BIG | 180 | if EINA_STATIC_BUILD_ONE_BIG |
197 | libeina_la_SOURCES += $(top_srcdir)/src/modules/eina/mp/one_big/eina_one_big.c | 181 | libeina_la_SOURCES += $(top_srcdir)/src/modules/eina/mp/one_big/eina_one_big.c |
198 | endif | 182 | endif |
diff --git a/src/lib/eina/eina_mempool.c b/src/lib/eina/eina_mempool.c index 385ea15928..389831510f 100644 --- a/src/lib/eina/eina_mempool.c +++ b/src/lib/eina/eina_mempool.c | |||
@@ -114,31 +114,11 @@ on_error: | |||
114 | 114 | ||
115 | /* Built-in backend's prototypes */ | 115 | /* Built-in backend's prototypes */ |
116 | 116 | ||
117 | #ifdef EINA_STATIC_BUILD_BUDDY | ||
118 | Eina_Bool buddy_init(void); | ||
119 | void buddy_shutdown(void); | ||
120 | #endif | ||
121 | |||
122 | #ifdef EINA_STATIC_BUILD_CHAINED_POOL | 117 | #ifdef EINA_STATIC_BUILD_CHAINED_POOL |
123 | Eina_Bool chained_init(void); | 118 | Eina_Bool chained_init(void); |
124 | void chained_shutdown(void); | 119 | void chained_shutdown(void); |
125 | #endif | 120 | #endif |
126 | 121 | ||
127 | #ifdef EINA_STATIC_BUILD_EMEMOA_FIXED | ||
128 | Eina_Bool ememoa_fixed_init(void); | ||
129 | void ememoa_fixed_shutdown(void); | ||
130 | #endif | ||
131 | |||
132 | #ifdef EINA_STATIC_BUILD_EMEMOA_UNKNOWN | ||
133 | Eina_Bool ememoa_unknown_init(void); | ||
134 | void ememoa_unknown_shutdown(void); | ||
135 | #endif | ||
136 | |||
137 | #ifdef EINA_STATIC_BUILD_FIXED_BITMAP | ||
138 | Eina_Bool fixed_bitmap_init(void); | ||
139 | void fixed_bitmap_shutdown(void); | ||
140 | #endif | ||
141 | |||
142 | #ifdef EINA_STATIC_BUILD_ONE_BIG | 122 | #ifdef EINA_STATIC_BUILD_ONE_BIG |
143 | Eina_Bool one_big_init(void); | 123 | Eina_Bool one_big_init(void); |
144 | void one_big_shutdown(void); | 124 | void one_big_shutdown(void); |
@@ -235,21 +215,9 @@ eina_mempool_init(void) | |||
235 | eina_module_list_load(_modules); | 215 | eina_module_list_load(_modules); |
236 | 216 | ||
237 | /* builtin backends */ | 217 | /* builtin backends */ |
238 | #ifdef EINA_STATIC_BUILD_BUDDY | ||
239 | buddy_init(); | ||
240 | #endif | ||
241 | #ifdef EINA_STATIC_BUILD_CHAINED_POOL | 218 | #ifdef EINA_STATIC_BUILD_CHAINED_POOL |
242 | chained_init(); | 219 | chained_init(); |
243 | #endif | 220 | #endif |
244 | #ifdef EINA_STATIC_BUILD_EMEMOA_FIXED | ||
245 | ememoa_fixed_init(); | ||
246 | #endif | ||
247 | #ifdef EINA_STATIC_BUILD_EMEMOA_UNKNOWN | ||
248 | ememoa_unknown_init(); | ||
249 | #endif | ||
250 | #ifdef EINA_STATIC_BUILD_FIXED_BITMAP | ||
251 | fixed_bitmap_init(); | ||
252 | #endif | ||
253 | #ifdef EINA_STATIC_BUILD_ONE_BIG | 221 | #ifdef EINA_STATIC_BUILD_ONE_BIG |
254 | one_big_init(); | 222 | one_big_init(); |
255 | #endif | 223 | #endif |
@@ -270,21 +238,9 @@ Eina_Bool | |||
270 | eina_mempool_shutdown(void) | 238 | eina_mempool_shutdown(void) |
271 | { | 239 | { |
272 | /* builtin backends */ | 240 | /* builtin backends */ |
273 | #ifdef EINA_STATIC_BUILD_BUDDY | ||
274 | buddy_shutdown(); | ||
275 | #endif | ||
276 | #ifdef EINA_STATIC_BUILD_CHAINED_POOL | 241 | #ifdef EINA_STATIC_BUILD_CHAINED_POOL |
277 | chained_shutdown(); | 242 | chained_shutdown(); |
278 | #endif | 243 | #endif |
279 | #ifdef EINA_STATIC_BUILD_EMEMOA_FIXED | ||
280 | ememoa_fixed_shutdown(); | ||
281 | #endif | ||
282 | #ifdef EINA_STATIC_BUILD_EMEMOA_UNKNOWN | ||
283 | ememoa_unknown_shutdown(); | ||
284 | #endif | ||
285 | #ifdef EINA_STATIC_BUILD_FIXED_BITMAP | ||
286 | fixed_bitmap_shutdown(); | ||
287 | #endif | ||
288 | #ifdef EINA_STATIC_BUILD_ONE_BIG | 244 | #ifdef EINA_STATIC_BUILD_ONE_BIG |
289 | one_big_shutdown(); | 245 | one_big_shutdown(); |
290 | #endif | 246 | #endif |
diff --git a/src/lib/eina/eina_mempool.h b/src/lib/eina/eina_mempool.h index 796bc9ec9c..5ece88dd93 100644 --- a/src/lib/eina/eina_mempool.h +++ b/src/lib/eina/eina_mempool.h | |||
@@ -31,25 +31,11 @@ | |||
31 | * | 31 | * |
32 | * Several mempool are available: | 32 | * Several mempool are available: |
33 | * | 33 | * |
34 | * @li @c buddy: It uses the | ||
35 | * <a href="http://en.wikipedia.org/wiki/Buddy_memory_allocation">"buddy | ||
36 | * allocator" algorithm</a> but the Eina implementation differs in the | ||
37 | * sense that the chunk information is not stored on the chunk itself, | ||
38 | * but on another memory area. This is useful for cases where the | ||
39 | * memory to manage might be slower to access, or limited (like video | ||
40 | * memory). | ||
41 | * @li @c chained_pool: It is the default one. It allocates a big | 34 | * @li @c chained_pool: It is the default one. It allocates a big |
42 | * chunk of memory with malloc() and split the result in chunks of the | 35 | * chunk of memory with malloc() and split the result in chunks of the |
43 | * requested size that are pushed inside a stack. When requested, it | 36 | * requested size that are pushed inside a stack. When requested, it |
44 | * takes this pointer from the stack to give them to whoever wants | 37 | * takes this pointer from the stack to give them to whoever wants |
45 | * them. | 38 | * them. |
46 | * @li @c ememoa_fixed and @c ememoa_unknown: experimental allocators | ||
47 | * which could be useful when a fixed amount of memory is needed. | ||
48 | * @li @c fixed_bitmap: It allocates with malloc) 32* the requested | ||
49 | * size and push the pool pointer in an rbtree. To find empty space in | ||
50 | * a pool, it will just search for the first bit set in an int (32 | ||
51 | * bits). Then, when a pointer is freed, it will do a search inside | ||
52 | * the rbtree. | ||
53 | * @li @c pass_through: it just call malloc() and free(). It may be | 39 | * @li @c pass_through: it just call malloc() and free(). It may be |
54 | * faster on some computers than using our own allocators (like having | 40 | * faster on some computers than using our own allocators (like having |
55 | * a huge L2 cache, over 4MB). | 41 | * a huge L2 cache, over 4MB). |
diff --git a/src/modules/eina/mp/Makefile.am b/src/modules/eina/mp/Makefile.am index 435d57a96a..cb6d26de25 100644 --- a/src/modules/eina/mp/Makefile.am +++ b/src/modules/eina/mp/Makefile.am | |||
@@ -2,36 +2,12 @@ MAINTAINERCLEANFILES = Makefile.in | |||
2 | 2 | ||
3 | SUBDIRS = | 3 | SUBDIRS = |
4 | 4 | ||
5 | if EINA_BUILD_BUDDY | ||
6 | if !EINA_STATIC_BUILD_BUDDY | ||
7 | SUBDIRS += buddy | ||
8 | endif | ||
9 | endif | ||
10 | |||
11 | if EINA_BUILD_CHAINED_POOL | 5 | if EINA_BUILD_CHAINED_POOL |
12 | if !EINA_STATIC_BUILD_CHAINED_POOL | 6 | if !EINA_STATIC_BUILD_CHAINED_POOL |
13 | SUBDIRS += chained_pool | 7 | SUBDIRS += chained_pool |
14 | endif | 8 | endif |
15 | endif | 9 | endif |
16 | 10 | ||
17 | if EINA_BUILD_EMEMOA_FIXED | ||
18 | if !EINA_STATIC_BUILD_EMEMOA_FIXED | ||
19 | SUBDIRS += ememoa_fixed | ||
20 | endif | ||
21 | endif | ||
22 | |||
23 | if EINA_BUILD_EMEMOA_UNKNOWN | ||
24 | if !EINA_STATIC_BUILD_EMEMOA_UNKNOWN | ||
25 | SUBDIRS += ememoa_unknown | ||
26 | endif | ||
27 | endif | ||
28 | |||
29 | if EINA_BUILD_FIXED_BITMAP | ||
30 | if !EINA_STATIC_BUILD_FIXED_BITMAP | ||
31 | SUBDIRS += fixed_bitmap | ||
32 | endif | ||
33 | endif | ||
34 | |||
35 | if EINA_BUILD_ONE_BIG | 11 | if EINA_BUILD_ONE_BIG |
36 | if !EINA_STATIC_BUILD_ONE_BIG | 12 | if !EINA_STATIC_BUILD_ONE_BIG |
37 | SUBDIRS += one_big | 13 | SUBDIRS += one_big |
diff --git a/src/modules/eina/mp/buddy/Makefile.am b/src/modules/eina/mp/buddy/Makefile.am deleted file mode 100644 index 4dc40aaf05..0000000000 --- a/src/modules/eina/mp/buddy/Makefile.am +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | MAINTAINERCLEANFILES = Makefile.in | ||
2 | |||
3 | AM_CPPFLAGS = \ | ||
4 | -I. \ | ||
5 | -I$(top_srcdir)/src/lib/eina \ | ||
6 | -I$(top_builddir)/src/lib/eina \ | ||
7 | -I$(top_srcdir)/src/lib/eina \ | ||
8 | -I$(top_builddir)/src/lib/eina \ | ||
9 | @EFL_EINA_BUILD@ | ||
10 | |||
11 | controllerdir = $(libdir)/eina/modules/mp/buddy/$(MODULE_ARCH) | ||
12 | controller_LTLIBRARIES = module.la | ||
13 | |||
14 | module_la_SOURCES = eina_buddy.c | ||
15 | |||
16 | module_la_CFLAGS = @EINA_CFLAGS@ | ||
17 | module_la_LIBADD = $(top_builddir)/src/lib/eina/libeina.la @EINA_LIBS@ | ||
18 | module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version | ||
19 | module_la_LIBTOOLFLAGS = --tag=disable-static | ||
20 | |||
21 | install-data-hook: | ||
22 | rm -f $(DESTDIR)$(controllerdir)/$(controller_LTLIBRARIES) | ||
23 | uninstall-hook: | ||
24 | rm -f $(DESTDIR)$(controllerdir)/module.* | ||
25 | |||
26 | clean-local: | ||
27 | rm -rf *.gcno | ||
diff --git a/src/modules/eina/mp/buddy/eina_buddy.c b/src/modules/eina/mp/buddy/eina_buddy.c deleted file mode 100644 index 8344c9db59..0000000000 --- a/src/modules/eina/mp/buddy/eina_buddy.c +++ /dev/null | |||
@@ -1,292 +0,0 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2009 Jorge Luis Zapata Muga | ||
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 | /* | ||
20 | * This is a naive 'buddy' allocator following Knuth's documentation. | ||
21 | * The main difference is that we dont store the block information | ||
22 | * on the block memory itself but on another malloc'd area. | ||
23 | * This is useful for managing memory which isn't as fast as the main | ||
24 | * memory like the video memory | ||
25 | * The algorithm uses an area to store the linked list of blocks. | ||
26 | * Each block size is equal to the minimum allocatable block size for | ||
27 | * the memory pool and the number of blocks is equal to the size of the | ||
28 | * memory pool divided by the block size. | ||
29 | */ | ||
30 | #ifdef HAVE_CONFIG_H | ||
31 | # include "config.h" | ||
32 | #endif | ||
33 | |||
34 | #include <stdio.h> | ||
35 | |||
36 | #include "eina_types.h" | ||
37 | #include "eina_inlist.h" | ||
38 | #include "eina_module.h" | ||
39 | #include "eina_mempool.h" | ||
40 | #include "eina_private.h" | ||
41 | |||
42 | typedef struct _Block | ||
43 | { | ||
44 | EINA_INLIST; | ||
45 | Eina_Bool available : 1; | ||
46 | unsigned short int order : 7; /* final order is order + min_order */ | ||
47 | } Block; | ||
48 | |||
49 | typedef struct _Buddy | ||
50 | { | ||
51 | void *heap; /* start address of the heap */ | ||
52 | size_t size; /* total size in bytes of the heap */ | ||
53 | unsigned int min_order; /* minimum size is 1 << min_order */ | ||
54 | unsigned int max_order; /* maximum size is 1 << max_order */ | ||
55 | unsigned int num_order; /* number of orders */ | ||
56 | Eina_Inlist **areas; /* one area per order */ | ||
57 | Block *blocks; /* the allocated block information */ | ||
58 | } Buddy; | ||
59 | |||
60 | /* get the minimum order greater or equal to size */ | ||
61 | static inline unsigned int _get_order(Buddy *b, size_t size) | ||
62 | { | ||
63 | unsigned int i; | ||
64 | size_t bytes; | ||
65 | |||
66 | bytes = 1 << b->min_order; | ||
67 | for (i = 0; bytes < size && i < b->num_order; i++) | ||
68 | { | ||
69 | bytes += bytes; | ||
70 | } | ||
71 | //printf("order for size %d is %d\n", size, i + b->min_order); | ||
72 | return i; | ||
73 | } | ||
74 | |||
75 | static inline void *_get_offset(Buddy *b, Block *block) | ||
76 | { | ||
77 | void *ret; | ||
78 | |||
79 | ret = (char *)b->heap + ((block - &b->blocks[0]) << b->min_order); | ||
80 | return ret; | ||
81 | } | ||
82 | |||
83 | static void *_init(EINA_UNUSED const char *context, | ||
84 | EINA_UNUSED const char *options, | ||
85 | va_list args) | ||
86 | { | ||
87 | Buddy *b; | ||
88 | int i; | ||
89 | size_t bytes; | ||
90 | size_t size; | ||
91 | size_t min_order; | ||
92 | void *heap; | ||
93 | |||
94 | heap = va_arg(args, void *); | ||
95 | size = va_arg(args, size_t); | ||
96 | min_order = va_arg(args, int); | ||
97 | /* the minimum order we support is 15 (32K) */ | ||
98 | min_order = min_order < 15 ? 15 : min_order; | ||
99 | bytes = 1 << min_order; | ||
100 | for (i = 0; bytes <= size; i++) | ||
101 | { | ||
102 | bytes += bytes; | ||
103 | } | ||
104 | if (!i) | ||
105 | return NULL; | ||
106 | |||
107 | b = malloc(sizeof(Buddy)); | ||
108 | b->heap = heap; | ||
109 | b->size = size; | ||
110 | b->min_order = min_order; | ||
111 | b->max_order = min_order + i - 1; | ||
112 | b->num_order = i; | ||
113 | b->areas = calloc(b->num_order, sizeof(Eina_Inlist *)); | ||
114 | b->blocks = calloc(1 << (b->num_order - 1), sizeof(Block)); | ||
115 | /* setup the initial free area */ | ||
116 | b->blocks[0].available = EINA_TRUE; | ||
117 | b->areas[b->num_order - 1] = EINA_INLIST_GET(&(b->blocks[0])); | ||
118 | |||
119 | return b; | ||
120 | } | ||
121 | |||
122 | static void _shutdown(void *data) | ||
123 | { | ||
124 | Buddy *b = data; | ||
125 | |||
126 | free(b->blocks); | ||
127 | free(b->areas); | ||
128 | free(b); | ||
129 | } | ||
130 | |||
131 | static void _free(void *data, void *element) | ||
132 | { | ||
133 | Buddy *b = data; | ||
134 | Block *block, *buddy; | ||
135 | size_t offset; | ||
136 | size_t idx; | ||
137 | |||
138 | offset = (unsigned char *)element - (unsigned char *)b->heap; | ||
139 | if (offset > b->size) | ||
140 | return; | ||
141 | |||
142 | idx = offset >> b->min_order; | ||
143 | block = &b->blocks[idx]; | ||
144 | |||
145 | //printf("free %x idx = %d order = %d buddy = %d\n", offset, idx, block->order, idx ^ (1 << block->order)); | ||
146 | /* we should always work with the buddy at right */ | ||
147 | if (idx & (1 << block->order)) | ||
148 | { | ||
149 | Block *left; | ||
150 | |||
151 | idx = idx ^ (1 << block->order); | ||
152 | left = &b->blocks[idx]; | ||
153 | if (!left->available) | ||
154 | goto end; | ||
155 | else | ||
156 | { | ||
157 | buddy = block; | ||
158 | block = left; | ||
159 | b->areas[block->order] = eina_inlist_remove(b->areas[block->order], | ||
160 | EINA_INLIST_GET(block)); | ||
161 | block->order++; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | check: | ||
166 | /* already on the last order */ | ||
167 | if (block->order + b->min_order == b->max_order) | ||
168 | { | ||
169 | goto end; /* get the buddy */ | ||
170 | |||
171 | } | ||
172 | |||
173 | buddy = &b->blocks[idx ^ (1 << block->order)]; | ||
174 | if (!buddy->available) | ||
175 | { | ||
176 | goto end; /* merge two blocks */ | ||
177 | |||
178 | } | ||
179 | |||
180 | b->areas[block->order] = eina_inlist_remove(b->areas[block->order], | ||
181 | EINA_INLIST_GET(buddy)); | ||
182 | block->order++; | ||
183 | goto check; | ||
184 | end: | ||
185 | /* add the block to the free list */ | ||
186 | block->available = EINA_TRUE; | ||
187 | b->areas[block->order] = eina_inlist_append(b->areas[block->order], | ||
188 | EINA_INLIST_GET(block)); | ||
189 | } | ||
190 | |||
191 | static void *_alloc(void *data, unsigned int size) | ||
192 | { | ||
193 | Buddy *b = data; | ||
194 | Block *block, *buddy; | ||
195 | unsigned int k, j; | ||
196 | |||
197 | k = j = _get_order(b, size); | ||
198 | /* get a free list of order k where k <= j <= max_order */ | ||
199 | while ((j < b->num_order) && !b->areas[j]) | ||
200 | j++; | ||
201 | /* check that the order is on our range */ | ||
202 | if (j + b->min_order > b->max_order) | ||
203 | return NULL; | ||
204 | |||
205 | /* get a free element on this order, if not, go splitting until we find one */ | ||
206 | //printf("getting order %d (%d) for size %d\n", j, k, size); | ||
207 | found: | ||
208 | if (j == k) | ||
209 | { | ||
210 | void *ret; | ||
211 | |||
212 | block = EINA_INLIST_CONTAINER_GET(b->areas[j], Block); | ||
213 | block->available = EINA_FALSE; | ||
214 | block->order = j; | ||
215 | /* remove the block from the list */ | ||
216 | b->areas[j] = eina_inlist_remove(b->areas[j], EINA_INLIST_GET(block)); | ||
217 | ret = _get_offset(b, block); | ||
218 | |||
219 | return ret; | ||
220 | } | ||
221 | |||
222 | block = EINA_INLIST_CONTAINER_GET(b->areas[j], Block); | ||
223 | /* split */ | ||
224 | b->areas[j] = eina_inlist_remove(b->areas[j], EINA_INLIST_GET(block)); | ||
225 | j--; | ||
226 | b->areas[j] = eina_inlist_append(b->areas[j], EINA_INLIST_GET(block)); | ||
227 | buddy = block + (1 << j); | ||
228 | buddy->order = j; | ||
229 | buddy->available = EINA_TRUE; | ||
230 | b->areas[j] = eina_inlist_append(b->areas[j], EINA_INLIST_GET(buddy)); | ||
231 | |||
232 | goto found; | ||
233 | } | ||
234 | |||
235 | static void _statistics(void *data) | ||
236 | { | ||
237 | Buddy *b = data; | ||
238 | unsigned int i; | ||
239 | |||
240 | printf("Information:\n"); | ||
241 | printf( | ||
242 | "size = %zu, min_order = %d, max_order = %d, num_order = %d, num_blocks = %d (%uKB)\n", | ||
243 | b->size, | ||
244 | b->min_order, | ||
245 | b->max_order, | ||
246 | b->num_order, | ||
247 | 1 << b->num_order, | ||
248 | ((1 << (b->num_order)) * sizeof(Block)) / 1024); | ||
249 | printf("Area dumping:"); | ||
250 | /* iterate over the free lists and dump the maps */ | ||
251 | for (i = 0; i < b->num_order; i++) | ||
252 | { | ||
253 | Block *block; | ||
254 | |||
255 | printf("\n2^%d:", b->min_order + i); | ||
256 | EINA_INLIST_FOREACH(b->areas[i], block) | ||
257 | { | ||
258 | printf(" %d", (block - &b->blocks[0])); | ||
259 | } | ||
260 | } | ||
261 | printf("\nBlocks dumping:\n"); | ||
262 | } | ||
263 | |||
264 | static Eina_Mempool_Backend _backend = { | ||
265 | "buddy", | ||
266 | &_init, | ||
267 | &_free, | ||
268 | &_alloc, | ||
269 | NULL, /* realloc */ | ||
270 | NULL, /* garbage collect */ | ||
271 | &_statistics, | ||
272 | &_shutdown, | ||
273 | NULL /* repack */ | ||
274 | }; | ||
275 | |||
276 | Eina_Bool buddy_init(void) | ||
277 | { | ||
278 | return eina_mempool_register(&_backend); | ||
279 | } | ||
280 | |||
281 | void buddy_shutdown(void) | ||
282 | { | ||
283 | eina_mempool_unregister(&_backend); | ||
284 | } | ||
285 | |||
286 | |||
287 | #ifndef EINA_STATIC_BUILD_BUDDY | ||
288 | |||
289 | EINA_MODULE_INIT(buddy_init); | ||
290 | EINA_MODULE_SHUTDOWN(buddy_shutdown); | ||
291 | |||
292 | #endif /* ! EINA_STATIC_BUILD_BUDDY */ | ||
diff --git a/src/modules/eina/mp/ememoa_fixed/Makefile.am b/src/modules/eina/mp/ememoa_fixed/Makefile.am deleted file mode 100644 index 09c12ca36d..0000000000 --- a/src/modules/eina/mp/ememoa_fixed/Makefile.am +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | MAINTAINERCLEANFILES = Makefile.in | ||
2 | |||
3 | AM_CPPFLAGS = \ | ||
4 | -I. \ | ||
5 | -I$(top_srcdir)/src/lib/eina \ | ||
6 | -I$(top_builddir)/src/lib/eina \ | ||
7 | -I$(top_srcdir)/src/lib/eina \ | ||
8 | -I$(top_builddir)/src/lib/eina \ | ||
9 | @EMEMOA_CFLAGS@ \ | ||
10 | @EFL_EINA_BUILD@ | ||
11 | |||
12 | controllerdir = $(libdir)/eina/modules/mp/ememoa_fixed/$(MODULE_ARCH) | ||
13 | controller_LTLIBRARIES = module.la | ||
14 | |||
15 | module_la_SOURCES = eina_ememoa_fixed.c | ||
16 | |||
17 | module_la_CFLAGS = @EINA_CFLAGS@ | ||
18 | module_la_LIBADD = $(top_builddir)/src/lib/eina/libeina.la @EMEMOA_LIBS@ @EINA_LIBS@ | ||
19 | module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version | ||
20 | module_la_LIBTOOLFLAGS = --tag=disable-static | ||
21 | |||
22 | install-data-hook: | ||
23 | rm -f $(DESTDIR)$(controllerdir)/$(controller_LTLIBRARIES) | ||
24 | uninstall-hook: | ||
25 | rm -f $(DESTDIR)$(controllerdir)/module.* | ||
26 | |||
27 | clean-local: | ||
28 | rm -rf *.gcno | ||
diff --git a/src/modules/eina/mp/ememoa_fixed/eina_ememoa_fixed.c b/src/modules/eina/mp/ememoa_fixed/eina_ememoa_fixed.c deleted file mode 100644 index 9b2deb6e89..0000000000 --- a/src/modules/eina/mp/ememoa_fixed/eina_ememoa_fixed.c +++ /dev/null | |||
@@ -1,176 +0,0 @@ | |||
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 | |||
27 | #include "eina_inlist.h" | ||
28 | #include "eina_error.h" | ||
29 | #include "eina_module.h" | ||
30 | #include "eina_mempool.h" | ||
31 | |||
32 | #include "eina_private.h" | ||
33 | |||
34 | typedef struct _Eina_Ememoa_Fixed_Mempool Eina_Ememoa_Fixed_Mempool; | ||
35 | struct _Eina_Ememoa_Fixed_Mempool | ||
36 | { | ||
37 | struct ememoa_mempool_desc_s *desc; | ||
38 | int pool; | ||
39 | }; | ||
40 | |||
41 | static void * | ||
42 | eina_ememoa_fixed_malloc(void *data, EINA_UNUSED unsigned int size) | ||
43 | { | ||
44 | Eina_Ememoa_Fixed_Mempool *efm = data; | ||
45 | |||
46 | return ememoa_mempool_fixed_pop_object(efm->pool); | ||
47 | } | ||
48 | |||
49 | static void | ||
50 | eina_ememoa_fixed_free(void *data, void *ptr) | ||
51 | { | ||
52 | Eina_Ememoa_Fixed_Mempool *efm = data; | ||
53 | |||
54 | ememoa_mempool_fixed_push_object(efm->pool, ptr); | ||
55 | } | ||
56 | |||
57 | static void * | ||
58 | eina_ememoa_fixed_realloc(EINA_UNUSED void *data, | ||
59 | EINA_UNUSED void *element, | ||
60 | EINA_UNUSED unsigned int size) | ||
61 | { | ||
62 | return NULL; | ||
63 | } | ||
64 | |||
65 | static void | ||
66 | eina_ememoa_fixed_gc(void *data) | ||
67 | { | ||
68 | Eina_Ememoa_Fixed_Mempool *efm = data; | ||
69 | |||
70 | ememoa_mempool_fixed_garbage_collect(efm->pool); | ||
71 | } | ||
72 | |||
73 | static void | ||
74 | eina_ememoa_fixed_statistics(void *data) | ||
75 | { | ||
76 | Eina_Ememoa_Fixed_Mempool *efm = data; | ||
77 | |||
78 | ememoa_mempool_fixed_display_statistic(efm->pool); | ||
79 | (void)efm; | ||
80 | } | ||
81 | |||
82 | static void * | ||
83 | eina_ememoa_fixed_init(const char *context, | ||
84 | EINA_UNUSED const char *option, | ||
85 | va_list args) | ||
86 | { | ||
87 | struct ememoa_mempool_desc_s *desc = NULL; | ||
88 | Eina_Ememoa_Fixed_Mempool *efm = NULL; | ||
89 | Eina_Bool thread_protect; | ||
90 | int context_length; | ||
91 | int item_size; | ||
92 | int pool_size; | ||
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 | item_size = va_arg(args, int); | ||
107 | pool_size = va_arg(args, int); | ||
108 | thread_protect = va_arg(args, int); | ||
109 | |||
110 | efm = malloc(sizeof (Eina_Ememoa_Fixed_Mempool)); | ||
111 | if (!efm) | ||
112 | goto on_error; | ||
113 | |||
114 | efm->desc = desc; | ||
115 | efm->pool = ememoa_mempool_fixed_init( | ||
116 | item_size, | ||
117 | pool_size, | ||
118 | thread_protect ? | ||
119 | EMEMOA_THREAD_PROTECTION : 0, | ||
120 | efm->desc); | ||
121 | if (efm->pool < 0) | ||
122 | goto on_error; | ||
123 | |||
124 | return efm; | ||
125 | |||
126 | on_error: | ||
127 | if (desc) | ||
128 | free(desc); | ||
129 | |||
130 | if (efm) | ||
131 | free(efm); | ||
132 | |||
133 | return NULL; | ||
134 | } | ||
135 | |||
136 | static void | ||
137 | eina_ememoa_fixed_shutdown(void *data) | ||
138 | { | ||
139 | Eina_Ememoa_Fixed_Mempool *efm = data; | ||
140 | |||
141 | if (efm->desc) | ||
142 | free(efm->desc); | ||
143 | |||
144 | ememoa_mempool_fixed_clean(efm->pool); | ||
145 | free(efm); | ||
146 | } | ||
147 | |||
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, | ||
157 | .repack = NULL | ||
158 | }; | ||
159 | |||
160 | Eina_Bool ememoa_fixed_init(void) | ||
161 | { | ||
162 | return eina_mempool_register(&_eina_ememoa_mp_backend); | ||
163 | } | ||
164 | |||
165 | void ememoa_fixed_shutdown(void) | ||
166 | { | ||
167 | eina_mempool_unregister(&_eina_ememoa_mp_backend); | ||
168 | } | ||
169 | |||
170 | |||
171 | #ifndef EINA_STATIC_BUILD_EMEMOA_FIXED | ||
172 | |||
173 | EINA_MODULE_INIT(ememoa_fixed_init); | ||
174 | EINA_MODULE_SHUTDOWN(ememoa_fixed_shutdown); | ||
175 | |||
176 | #endif /* ! EINA_STATIC_BUILD_EMEMOA_FIXED */ | ||
diff --git a/src/modules/eina/mp/ememoa_unknown/Makefile.am b/src/modules/eina/mp/ememoa_unknown/Makefile.am deleted file mode 100644 index 5ab88a687c..0000000000 --- a/src/modules/eina/mp/ememoa_unknown/Makefile.am +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | MAINTAINERCLEANFILES = Makefile.in | ||
2 | |||
3 | AM_CPPFLAGS = \ | ||
4 | -I. \ | ||
5 | -I$(top_srcdir)/src/lib/eina \ | ||
6 | -I$(top_builddir)/src/lib/eina \ | ||
7 | -I$(top_srcdir)/src/lib/eina \ | ||
8 | -I$(top_builddir)/src/lib/eina \ | ||
9 | @EMEMOA_CFLAGS@ \ | ||
10 | @EFL_EINA_BUILD@ | ||
11 | |||
12 | controllerdir = $(libdir)/eina/modules/mp/ememoa_unknown/$(MODULE_ARCH) | ||
13 | controller_LTLIBRARIES = module.la | ||
14 | |||
15 | module_la_SOURCES = eina_ememoa_unknown.c | ||
16 | |||
17 | module_la_CFLAGS = @EINA_CFLAGS@ | ||
18 | module_la_LIBADD = $(top_builddir)/src/lib/eina/libeina.la @EMEMOA_LIBS@ @EINA_LIBS@ | ||
19 | module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version | ||
20 | module_la_LIBTOOLFLAGS = --tag=disable-static | ||
21 | |||
22 | install-data-hook: | ||
23 | rm -f $(DESTDIR)$(controllerdir)/$(controller_LTLIBRARIES) | ||
24 | uninstall-hook: | ||
25 | rm -f $(DESTDIR)$(controllerdir)/module.* | ||
26 | |||
27 | clean-local: | ||
28 | rm -rf *.gcno | ||
diff --git a/src/modules/eina/mp/ememoa_unknown/eina_ememoa_unknown.c b/src/modules/eina/mp/ememoa_unknown/eina_ememoa_unknown.c deleted file mode 100644 index 736bcc1939..0000000000 --- a/src/modules/eina/mp/ememoa_unknown/eina_ememoa_unknown.c +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
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 | EINA_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 */ | ||
diff --git a/src/modules/eina/mp/fixed_bitmap/Makefile.am b/src/modules/eina/mp/fixed_bitmap/Makefile.am deleted file mode 100644 index 784b740288..0000000000 --- a/src/modules/eina/mp/fixed_bitmap/Makefile.am +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | MAINTAINERCLEANFILES = Makefile.in | ||
2 | |||
3 | AM_CPPFLAGS = \ | ||
4 | -I. \ | ||
5 | -I$(top_srcdir)/src/lib/eina \ | ||
6 | -I$(top_builddir)/src/lib/eina \ | ||
7 | -I$(top_srcdir)/src/lib/eina \ | ||
8 | -I$(top_builddir)/src/lib/eina \ | ||
9 | @EFL_EINA_BUILD@ | ||
10 | |||
11 | controllerdir = $(libdir)/eina/modules/mp/fixed_bitmap/$(MODULE_ARCH) | ||
12 | controller_LTLIBRARIES = module.la | ||
13 | |||
14 | module_la_SOURCES = eina_fixed_bitmap.c | ||
15 | |||
16 | module_la_CFLAGS = @EINA_CFLAGS@ | ||
17 | module_la_LIBADD = $(top_builddir)/src/lib/eina/libeina.la @EINA_LIBS@ | ||
18 | module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version | ||
19 | module_la_LIBTOOLFLAGS = --tag=disable-static | ||
20 | |||
21 | install-data-hook: | ||
22 | rm -f $(DESTDIR)$(controllerdir)/$(controller_LTLIBRARIES) | ||
23 | uninstall-hook: | ||
24 | rm -f $(DESTDIR)$(controllerdir)/module.* | ||
25 | |||
26 | clean-local: | ||
27 | rm -rf *.gcno | ||
diff --git a/src/modules/eina/mp/fixed_bitmap/eina_fixed_bitmap.c b/src/modules/eina/mp/fixed_bitmap/eina_fixed_bitmap.c deleted file mode 100644 index 1fd55348db..0000000000 --- a/src/modules/eina/mp/fixed_bitmap/eina_fixed_bitmap.c +++ /dev/null | |||
@@ -1,270 +0,0 @@ | |||
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 | #ifndef _MSC_VER | ||
24 | # include <stdint.h> | ||
25 | #endif | ||
26 | #include <string.h> | ||
27 | #include <assert.h> | ||
28 | |||
29 | #ifdef HAVE_EVIL | ||
30 | # include <Evil.h> | ||
31 | #endif | ||
32 | |||
33 | #include "eina_inlist.h" | ||
34 | #include "eina_rbtree.h" | ||
35 | #include "eina_error.h" | ||
36 | |||
37 | #include "eina_mempool.h" | ||
38 | |||
39 | #include "eina_private.h" | ||
40 | |||
41 | typedef struct _Eina_Fixed_Bitmap Eina_Fixed_Bitmap; | ||
42 | typedef struct _Eina_Fixed_Bitmap_Pool Eina_Fixed_Bitmap_Pool; | ||
43 | |||
44 | struct _Eina_Fixed_Bitmap | ||
45 | { | ||
46 | Eina_Rbtree *lookup; | ||
47 | Eina_Inlist *head; | ||
48 | |||
49 | int item_size; | ||
50 | }; | ||
51 | |||
52 | struct _Eina_Fixed_Bitmap_Pool | ||
53 | { | ||
54 | EINA_RBTREE; | ||
55 | EINA_INLIST; | ||
56 | |||
57 | uint32_t bitmask; | ||
58 | }; | ||
59 | |||
60 | static inline size_t | ||
61 | _eina_rbtree_inlist_delta(void) | ||
62 | { | ||
63 | Eina_Fixed_Bitmap_Pool tmp; | ||
64 | void *a = &tmp.__rbtree; | ||
65 | void *b = &tmp.__in_list; | ||
66 | |||
67 | return (char *)a - (char *)b; | ||
68 | } | ||
69 | |||
70 | static Eina_Rbtree_Direction | ||
71 | _eina_fixed_cmp(const Eina_Rbtree *left, | ||
72 | const Eina_Rbtree *right, | ||
73 | EINA_UNUSED void *data) | ||
74 | { | ||
75 | if (left - right < 0) | ||
76 | return EINA_RBTREE_LEFT; | ||
77 | |||
78 | return EINA_RBTREE_RIGHT; | ||
79 | } | ||
80 | |||
81 | static int | ||
82 | _eina_fixed_cmp_key(const Eina_Rbtree *node, | ||
83 | const void *key, | ||
84 | EINA_UNUSED int length, | ||
85 | Eina_Fixed_Bitmap *mp) | ||
86 | { | ||
87 | const void *a = node; | ||
88 | const void *b = key; | ||
89 | ssize_t delta; | ||
90 | ssize_t limit; | ||
91 | |||
92 | limit = sizeof (Eina_Fixed_Bitmap_Pool) + mp->item_size * 32; | ||
93 | delta = (char *)a - (char *)b; | ||
94 | |||
95 | if (delta > 0) | ||
96 | return 1; | ||
97 | |||
98 | if (delta + limit < 0) | ||
99 | return -1; | ||
100 | |||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static void | ||
105 | _eina_fixed_bitmap_pool_free(Eina_Fixed_Bitmap_Pool *pool, | ||
106 | EINA_UNUSED void *data) | ||
107 | { | ||
108 | free(pool); | ||
109 | } | ||
110 | |||
111 | static void * | ||
112 | eina_fixed_bitmap_malloc(void *data, EINA_UNUSED unsigned int size) | ||
113 | { | ||
114 | Eina_Fixed_Bitmap *mp = data; | ||
115 | Eina_Fixed_Bitmap_Pool *pool = NULL; | ||
116 | void *ptr; | ||
117 | int idx; | ||
118 | |||
119 | if (mp->head) | ||
120 | { | ||
121 | pool = | ||
122 | (Eina_Fixed_Bitmap_Pool *)((unsigned char *)mp->head + | ||
123 | _eina_rbtree_inlist_delta()); | ||
124 | |||
125 | if (pool->bitmask == 0) | ||
126 | pool = NULL; | ||
127 | } | ||
128 | |||
129 | if (!pool) | ||
130 | { | ||
131 | eina_error_set(0); | ||
132 | pool = malloc(sizeof (Eina_Fixed_Bitmap_Pool) + mp->item_size * 32); | ||
133 | if (!pool) | ||
134 | { | ||
135 | eina_error_set(EINA_ERROR_OUT_OF_MEMORY); | ||
136 | return NULL; | ||
137 | } | ||
138 | |||
139 | pool->bitmask = 0xFFFFFFFF; | ||
140 | |||
141 | mp->head = eina_inlist_prepend(mp->head, EINA_INLIST_GET(pool)); | ||
142 | mp->lookup = eina_rbtree_inline_insert(mp->lookup, EINA_RBTREE_GET( | ||
143 | pool), | ||
144 | EINA_RBTREE_CMP_NODE_CB( | ||
145 | _eina_fixed_cmp), NULL); | ||
146 | } | ||
147 | |||
148 | idx = ffs(pool->bitmask) - 1; | ||
149 | pool->bitmask &= ~(1 << idx); | ||
150 | ptr = (unsigned char *)(pool + 1) + idx * mp->item_size; | ||
151 | |||
152 | if (pool->bitmask == 0) | ||
153 | mp->head = eina_inlist_demote(mp->head, EINA_INLIST_GET(pool)); | ||
154 | |||
155 | return ptr; | ||
156 | } | ||
157 | |||
158 | static void | ||
159 | eina_fixed_bitmap_free(void *data, void *ptr) | ||
160 | { | ||
161 | Eina_Fixed_Bitmap *mp = data; | ||
162 | Eina_Fixed_Bitmap_Pool *pool; | ||
163 | void *a; | ||
164 | Eina_Bool push_front = EINA_FALSE; | ||
165 | ssize_t delta; | ||
166 | |||
167 | pool = (Eina_Fixed_Bitmap_Pool *)eina_rbtree_inline_lookup( | ||
168 | mp->lookup, | ||
169 | ptr, | ||
170 | 0, | ||
171 | EINA_RBTREE_CMP_KEY_CB( | ||
172 | _eina_fixed_cmp_key), | ||
173 | mp); | ||
174 | if (!pool) | ||
175 | return; | ||
176 | |||
177 | if (pool->bitmask != 0xFFFFFFFF) | ||
178 | push_front = EINA_TRUE; | ||
179 | |||
180 | a = pool; | ||
181 | delta = | ||
182 | ((char *)ptr - (char *)a - | ||
183 | sizeof (Eina_Fixed_Bitmap_Pool)) / mp->item_size; | ||
184 | |||
185 | assert(delta >= 0 && delta < 32); | ||
186 | |||
187 | pool->bitmask |= (1 << (delta & 0x1F)); | ||
188 | |||
189 | if (pool->bitmask == 0xFFFFFFFF) | ||
190 | { | ||
191 | mp->head = eina_inlist_remove(mp->head, EINA_INLIST_GET(pool)); | ||
192 | mp->lookup = eina_rbtree_inline_remove(mp->lookup, EINA_RBTREE_GET( | ||
193 | pool), | ||
194 | EINA_RBTREE_CMP_NODE_CB( | ||
195 | _eina_fixed_cmp), NULL); | ||
196 | free(pool); | ||
197 | } | ||
198 | else if (push_front) | ||
199 | mp->head = eina_inlist_promote(mp->head, EINA_INLIST_GET(pool)); | ||
200 | } | ||
201 | |||
202 | static void * | ||
203 | eina_fixed_bitmap_realloc(EINA_UNUSED void *data, | ||
204 | EINA_UNUSED void *element, | ||
205 | EINA_UNUSED unsigned int size) | ||
206 | { | ||
207 | return NULL; | ||
208 | } | ||
209 | |||
210 | static void * | ||
211 | eina_fixed_bitmap_init(EINA_UNUSED const char *context, | ||
212 | EINA_UNUSED const char *option, | ||
213 | va_list args) | ||
214 | { | ||
215 | Eina_Fixed_Bitmap *mp; | ||
216 | int item_size; | ||
217 | |||
218 | mp = malloc(sizeof (Eina_Fixed_Bitmap)); | ||
219 | if (!mp) | ||
220 | return NULL; | ||
221 | |||
222 | item_size = va_arg(args, int); | ||
223 | |||
224 | mp->item_size = eina_mempool_alignof(item_size); | ||
225 | |||
226 | mp->lookup = NULL; | ||
227 | mp->head = NULL; | ||
228 | |||
229 | return mp; | ||
230 | } | ||
231 | |||
232 | static void | ||
233 | eina_fixed_bitmap_shutdown(void *data) | ||
234 | { | ||
235 | Eina_Fixed_Bitmap *mp = data; | ||
236 | |||
237 | eina_rbtree_delete(mp->lookup, | ||
238 | EINA_RBTREE_FREE_CB(_eina_fixed_bitmap_pool_free), NULL); | ||
239 | free(mp); | ||
240 | } | ||
241 | |||
242 | static Eina_Mempool_Backend _eina_fixed_bitmap_mp_backend = { | ||
243 | "fixed_bitmap", | ||
244 | &eina_fixed_bitmap_init, | ||
245 | &eina_fixed_bitmap_free, | ||
246 | &eina_fixed_bitmap_malloc, | ||
247 | &eina_fixed_bitmap_realloc, | ||
248 | NULL, | ||
249 | NULL, | ||
250 | &eina_fixed_bitmap_shutdown, | ||
251 | NULL | ||
252 | }; | ||
253 | |||
254 | Eina_Bool fixed_bitmap_init(void) | ||
255 | { | ||
256 | return eina_mempool_register(&_eina_fixed_bitmap_mp_backend); | ||
257 | } | ||
258 | |||
259 | void fixed_bitmap_shutdown(void) | ||
260 | { | ||
261 | eina_mempool_unregister(&_eina_fixed_bitmap_mp_backend); | ||
262 | } | ||
263 | |||
264 | #ifndef EINA_STATIC_BUILD_FIXED_BITMAP | ||
265 | |||
266 | EINA_MODULE_INIT(fixed_bitmap_init); | ||
267 | EINA_MODULE_SHUTDOWN(fixed_bitmap_shutdown); | ||
268 | |||
269 | #endif /* ! EINA_STATIC_BUILD_FIXED_BITMAP */ | ||
270 | |||