summaryrefslogtreecommitdiff
path: root/src/modules/eina/mp/ememoa_unknown
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-09-16 10:57:48 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-09-16 10:57:48 +0000
commit785f2a6b3a70454ecfe94addc6480ebf20c44c13 (patch)
tree17a195d2c1f022cd480fd0e0b95be5035ad915e2 /src/modules/eina/mp/ememoa_unknown
parentdfc0331373c3f98df7cb996abc588c7dcf44af0a (diff)
merge : add eina
currently, examples, tests and benchmark are not set. That's the next things i'll do SVN revision: 76710
Diffstat (limited to 'src/modules/eina/mp/ememoa_unknown')
-rw-r--r--src/modules/eina/mp/ememoa_unknown/Makefile.am28
-rw-r--r--src/modules/eina/mp/ememoa_unknown/eina_ememoa_unknown.c182
2 files changed, 210 insertions, 0 deletions
diff --git a/src/modules/eina/mp/ememoa_unknown/Makefile.am b/src/modules/eina/mp/ememoa_unknown/Makefile.am
new file mode 100644
index 0000000000..9713137110
--- /dev/null
+++ b/src/modules/eina/mp/ememoa_unknown/Makefile.am
@@ -0,0 +1,28 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I. \
5-I$(top_srcdir)/src/include/eina \
6-I$(top_builddir)/src/include/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
new file mode 100644
index 0000000000..56b99f66c9
--- /dev/null
+++ b/src/modules/eina/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
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 __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 */