summaryrefslogtreecommitdiff
path: root/legacy/eet/src/lib/eet_alloc.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-12-02 16:10:41 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-12-02 16:10:41 +0000
commita1af23ce2801556074f636e7aec772612649615e (patch)
tree4e53b8dba40ed1b6b2c355b47266990d858160de /legacy/eet/src/lib/eet_alloc.c
parent323cd79c4caacec427e8ad3aaa3751c4f49adf03 (diff)
move majority of allocations to mempool allocators similar to ecore-con
SVN revision: 65825
Diffstat (limited to 'legacy/eet/src/lib/eet_alloc.c')
-rw-r--r--legacy/eet/src/lib/eet_alloc.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/legacy/eet/src/lib/eet_alloc.c b/legacy/eet/src/lib/eet_alloc.c
new file mode 100644
index 0000000000..2f62b1b446
--- /dev/null
+++ b/legacy/eet/src/lib/eet_alloc.c
@@ -0,0 +1,95 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include "Eet.h"
7#include "Eet_private.h"
8
9typedef struct _Eet_Mempool Eet_Mempool;
10struct _Eet_Mempool
11{
12 const char *name;
13 Eina_Mempool *mp;
14 size_t size;
15};
16
17#define GENERIC_ALLOC_FREE(TYPE, Type) \
18 Eet_Mempool Type##_mp = { #TYPE, NULL, sizeof (TYPE) }; \
19 \
20 TYPE * \
21 Type##_malloc(unsigned int num) \
22 { \
23 return eina_mempool_malloc(Type##_mp.mp, num * sizeof (TYPE)); \
24 } \
25 TYPE * \
26 Type##_calloc(unsigned int num) \
27 { \
28 return eina_mempool_calloc(Type##_mp.mp, num * sizeof (TYPE)); \
29 } \
30 void \
31 Type##_mp_free(TYPE *e) \
32 { \
33 eina_mempool_free(Type##_mp.mp, e); \
34 }
35
36GENERIC_ALLOC_FREE(Eet_File_Directory, eet_file_directory);
37GENERIC_ALLOC_FREE(Eet_File_Node, eet_file_node);
38GENERIC_ALLOC_FREE(Eet_File_Header, eet_file_header);
39GENERIC_ALLOC_FREE(Eet_Dictionary, eet_dictionary);
40GENERIC_ALLOC_FREE(Eet_File, eet_file);
41GENERIC_ALLOC_FREE(Eet_String, eet_string);
42
43static Eet_Mempool *mempool_array[] = {
44 &eet_file_directory_mp,
45 &eet_file_node_mp,
46 &eet_file_header_mp,
47 &eet_dictionary_mp,
48 &eet_file_mp,
49 &eet_string_mp
50};
51
52Eina_Bool
53eet_mempool_init(void)
54{
55 const char *choice;
56 unsigned int i;
57
58 choice = getenv("EINA_MEMPOOL");
59 if ((!choice) || (!choice[0]))
60 choice = "chained_mempool";
61
62 for (i = 0; i < sizeof (mempool_array) / sizeof (mempool_array[0]); ++i)
63 {
64 retry:
65 mempool_array[i]->mp = eina_mempool_add(choice, mempool_array[i]->name, NULL, mempool_array[i]->size, 64);
66 if (!mempool_array[i]->mp)
67 {
68 if (!strcmp(choice, "pass_through"))
69 {
70 ERR("Falling back to pass through ! Previously tried '%s' mempool.", choice);
71 choice = "pass_through";
72 goto retry;
73 }
74 else
75 {
76 ERR("Impossible to allocate mempool '%s' !", choice);
77 return EINA_FALSE;
78 }
79 }
80 }
81 return EINA_TRUE;
82}
83
84void
85eet_mempool_shutdown(void)
86{
87 unsigned int i;
88
89 for (i = 0; i < sizeof (mempool_array) / sizeof (mempool_array[0]); ++i)
90 {
91 eina_mempool_del(mempool_array[i]->mp);
92 mempool_array[i]->mp = NULL;
93 }
94}
95