summaryrefslogtreecommitdiff
path: root/src/modules/eina
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-10-10 19:57:53 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-10-10 19:57:53 +0000
commit4d35e4ca03005d2f7fcf75caa877deb804d2f48a (patch)
tree111aebc08432286f540329e39aa84fd379e23b33 /src/modules/eina
parent59ed22a467fb4918064e5fa9dc6c75bee37faeaf (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/modules/eina')
-rw-r--r--src/modules/eina/mp/Makefile.am24
-rw-r--r--src/modules/eina/mp/buddy/Makefile.am27
-rw-r--r--src/modules/eina/mp/buddy/eina_buddy.c292
-rw-r--r--src/modules/eina/mp/ememoa_fixed/Makefile.am28
-rw-r--r--src/modules/eina/mp/ememoa_fixed/eina_ememoa_fixed.c176
-rw-r--r--src/modules/eina/mp/ememoa_unknown/Makefile.am28
-rw-r--r--src/modules/eina/mp/ememoa_unknown/eina_ememoa_unknown.c182
-rw-r--r--src/modules/eina/mp/fixed_bitmap/Makefile.am27
-rw-r--r--src/modules/eina/mp/fixed_bitmap/eina_fixed_bitmap.c270
9 files changed, 0 insertions, 1054 deletions
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
3SUBDIRS = 3SUBDIRS =
4 4
5if EINA_BUILD_BUDDY
6if !EINA_STATIC_BUILD_BUDDY
7SUBDIRS += buddy
8endif
9endif
10
11if EINA_BUILD_CHAINED_POOL 5if EINA_BUILD_CHAINED_POOL
12if !EINA_STATIC_BUILD_CHAINED_POOL 6if !EINA_STATIC_BUILD_CHAINED_POOL
13SUBDIRS += chained_pool 7SUBDIRS += chained_pool
14endif 8endif
15endif 9endif
16 10
17if EINA_BUILD_EMEMOA_FIXED
18if !EINA_STATIC_BUILD_EMEMOA_FIXED
19SUBDIRS += ememoa_fixed
20endif
21endif
22
23if EINA_BUILD_EMEMOA_UNKNOWN
24if !EINA_STATIC_BUILD_EMEMOA_UNKNOWN
25SUBDIRS += ememoa_unknown
26endif
27endif
28
29if EINA_BUILD_FIXED_BITMAP
30if !EINA_STATIC_BUILD_FIXED_BITMAP
31SUBDIRS += fixed_bitmap
32endif
33endif
34
35if EINA_BUILD_ONE_BIG 11if EINA_BUILD_ONE_BIG
36if !EINA_STATIC_BUILD_ONE_BIG 12if !EINA_STATIC_BUILD_ONE_BIG
37SUBDIRS += one_big 13SUBDIRS += 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 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_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
11controllerdir = $(libdir)/eina/modules/mp/buddy/$(MODULE_ARCH)
12controller_LTLIBRARIES = module.la
13
14module_la_SOURCES = eina_buddy.c
15
16module_la_CFLAGS = @EINA_CFLAGS@
17module_la_LIBADD = $(top_builddir)/src/lib/eina/libeina.la @EINA_LIBS@
18module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
19module_la_LIBTOOLFLAGS = --tag=disable-static
20
21install-data-hook:
22 rm -f $(DESTDIR)$(controllerdir)/$(controller_LTLIBRARIES)
23uninstall-hook:
24 rm -f $(DESTDIR)$(controllerdir)/module.*
25
26clean-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
42typedef 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
49typedef 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 */
61static 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
75static 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
83static 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
122static void _shutdown(void *data)
123{
124 Buddy *b = data;
125
126 free(b->blocks);
127 free(b->areas);
128 free(b);
129}
130
131static 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
165check:
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;
184end:
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
191static 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);
207found:
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
235static 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
264static 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
276Eina_Bool buddy_init(void)
277{
278 return eina_mempool_register(&_backend);
279}
280
281void buddy_shutdown(void)
282{
283 eina_mempool_unregister(&_backend);
284}
285
286
287#ifndef EINA_STATIC_BUILD_BUDDY
288
289EINA_MODULE_INIT(buddy_init);
290EINA_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 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_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
12controllerdir = $(libdir)/eina/modules/mp/ememoa_fixed/$(MODULE_ARCH)
13controller_LTLIBRARIES = module.la
14
15module_la_SOURCES = eina_ememoa_fixed.c
16
17module_la_CFLAGS = @EINA_CFLAGS@
18module_la_LIBADD = $(top_builddir)/src/lib/eina/libeina.la @EMEMOA_LIBS@ @EINA_LIBS@
19module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
20module_la_LIBTOOLFLAGS = --tag=disable-static
21
22install-data-hook:
23 rm -f $(DESTDIR)$(controllerdir)/$(controller_LTLIBRARIES)
24uninstall-hook:
25 rm -f $(DESTDIR)$(controllerdir)/module.*
26
27clean-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
34typedef struct _Eina_Ememoa_Fixed_Mempool Eina_Ememoa_Fixed_Mempool;
35struct _Eina_Ememoa_Fixed_Mempool
36{
37 struct ememoa_mempool_desc_s *desc;
38 int pool;
39};
40
41static void *
42eina_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
49static void
50eina_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
57static void *
58eina_ememoa_fixed_realloc(EINA_UNUSED void *data,
59 EINA_UNUSED void *element,
60 EINA_UNUSED unsigned int size)
61{
62 return NULL;
63}
64
65static void
66eina_ememoa_fixed_gc(void *data)
67{
68 Eina_Ememoa_Fixed_Mempool *efm = data;
69
70 ememoa_mempool_fixed_garbage_collect(efm->pool);
71}
72
73static void
74eina_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
82static void *
83eina_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
126on_error:
127 if (desc)
128 free(desc);
129
130 if (efm)
131 free(efm);
132
133 return NULL;
134}
135
136static void
137eina_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
148static 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
160Eina_Bool ememoa_fixed_init(void)
161{
162 return eina_mempool_register(&_eina_ememoa_mp_backend);
163}
164
165void ememoa_fixed_shutdown(void)
166{
167 eina_mempool_unregister(&_eina_ememoa_mp_backend);
168}
169
170
171#ifndef EINA_STATIC_BUILD_EMEMOA_FIXED
172
173EINA_MODULE_INIT(ememoa_fixed_init);
174EINA_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 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_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
12controllerdir = $(libdir)/eina/modules/mp/ememoa_unknown/$(MODULE_ARCH)
13controller_LTLIBRARIES = module.la
14
15module_la_SOURCES = eina_ememoa_unknown.c
16
17module_la_CFLAGS = @EINA_CFLAGS@
18module_la_LIBADD = $(top_builddir)/src/lib/eina/libeina.la @EMEMOA_LIBS@ @EINA_LIBS@
19module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
20module_la_LIBTOOLFLAGS = --tag=disable-static
21
22install-data-hook:
23 rm -f $(DESTDIR)$(controllerdir)/$(controller_LTLIBRARIES)
24uninstall-hook:
25 rm -f $(DESTDIR)$(controllerdir)/module.*
26
27clean-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
33typedef struct _Eina_Ememoa_Unknown_Size_Mempool
34Eina_Ememoa_Unknown_Size_Mempool;
35struct _Eina_Ememoa_Unknown_Size_Mempool
36{
37 struct ememoa_mempool_desc_s *desc;
38 int pool;
39};
40
41static void *
42eina_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
49static void
50eina_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
57static void *
58eina_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
65static void
66eina_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
73static void
74eina_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
81static void *
82eina_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
130on_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
143static void
144eina_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
155static 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
167Eina_Bool ememoa_unknown_init(void)
168{
169 return eina_mempool_register(&_eina_ememoa_unknown_mp_backend);
170}
171
172void ememoa_unknown_shutdown(void)
173{
174 eina_mempool_unregister(&_eina_ememoa_unknown_mp_backend);
175}
176
177#ifndef EINA_STATIC_BUILD_EMEMOA_UNKNOWN
178
179EINA_MODULE_INIT(ememoa_unknown_init);
180EINA_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 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_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
11controllerdir = $(libdir)/eina/modules/mp/fixed_bitmap/$(MODULE_ARCH)
12controller_LTLIBRARIES = module.la
13
14module_la_SOURCES = eina_fixed_bitmap.c
15
16module_la_CFLAGS = @EINA_CFLAGS@
17module_la_LIBADD = $(top_builddir)/src/lib/eina/libeina.la @EINA_LIBS@
18module_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
19module_la_LIBTOOLFLAGS = --tag=disable-static
20
21install-data-hook:
22 rm -f $(DESTDIR)$(controllerdir)/$(controller_LTLIBRARIES)
23uninstall-hook:
24 rm -f $(DESTDIR)$(controllerdir)/module.*
25
26clean-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
41typedef struct _Eina_Fixed_Bitmap Eina_Fixed_Bitmap;
42typedef struct _Eina_Fixed_Bitmap_Pool Eina_Fixed_Bitmap_Pool;
43
44struct _Eina_Fixed_Bitmap
45{
46 Eina_Rbtree *lookup;
47 Eina_Inlist *head;
48
49 int item_size;
50};
51
52struct _Eina_Fixed_Bitmap_Pool
53{
54 EINA_RBTREE;
55 EINA_INLIST;
56
57 uint32_t bitmask;
58};
59
60static 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
70static 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
81static 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
104static void
105_eina_fixed_bitmap_pool_free(Eina_Fixed_Bitmap_Pool *pool,
106 EINA_UNUSED void *data)
107{
108 free(pool);
109}
110
111static void *
112eina_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
158static void
159eina_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
202static void *
203eina_fixed_bitmap_realloc(EINA_UNUSED void *data,
204 EINA_UNUSED void *element,
205 EINA_UNUSED unsigned int size)
206{
207 return NULL;
208}
209
210static void *
211eina_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
232static void
233eina_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
242static 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
254Eina_Bool fixed_bitmap_init(void)
255{
256 return eina_mempool_register(&_eina_fixed_bitmap_mp_backend);
257}
258
259void fixed_bitmap_shutdown(void)
260{
261 eina_mempool_unregister(&_eina_fixed_bitmap_mp_backend);
262}
263
264#ifndef EINA_STATIC_BUILD_FIXED_BITMAP
265
266EINA_MODULE_INIT(fixed_bitmap_init);
267EINA_MODULE_SHUTDOWN(fixed_bitmap_shutdown);
268
269#endif /* ! EINA_STATIC_BUILD_FIXED_BITMAP */
270