aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_con/ecore_con_alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/lib/ecore_con/ecore_con_alloc.c')
-rw-r--r--libraries/ecore/src/lib/ecore_con/ecore_con_alloc.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_con/ecore_con_alloc.c b/libraries/ecore/src/lib/ecore_con/ecore_con_alloc.c
new file mode 100644
index 0000000..206948b
--- /dev/null
+++ b/libraries/ecore/src/lib/ecore_con/ecore_con_alloc.c
@@ -0,0 +1,99 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include "Ecore.h"
6#include "ecore_private.h"
7#include "Ecore_Con.h"
8#include "ecore_con_private.h"
9
10typedef struct _Ecore_Con_Mempool Ecore_Con_Mempool;
11struct _Ecore_Con_Mempool
12{
13 const char *name;
14 Eina_Mempool *mp;
15 size_t size;
16};
17
18#define GENERIC_ALLOC_FREE(TYPE, Type) \
19 Ecore_Con_Mempool Type##_mp = { #TYPE, NULL, sizeof (TYPE) }; \
20 \
21 TYPE * \
22 Type##_alloc(void) \
23 { \
24 return eina_mempool_malloc(Type##_mp.mp, sizeof (TYPE)); \
25 } \
26 \
27 void \
28 Type##_free(TYPE *e) \
29 { \
30 eina_mempool_free(Type##_mp.mp, e); \
31 }
32
33GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Add, ecore_con_event_client_add);
34GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Del, ecore_con_event_client_del);
35GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Write, ecore_con_event_client_write);
36GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Data, ecore_con_event_client_data);
37GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Error, ecore_con_event_server_error);
38GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Error, ecore_con_event_client_error);
39GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Add, ecore_con_event_server_add);
40GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Del, ecore_con_event_server_del);
41GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Write, ecore_con_event_server_write);
42GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Data, ecore_con_event_server_data);
43
44static Ecore_Con_Mempool *mempool_array[] = {
45 &ecore_con_event_client_add_mp,
46 &ecore_con_event_client_del_mp,
47 &ecore_con_event_client_write_mp,
48 &ecore_con_event_client_data_mp,
49 &ecore_con_event_server_error_mp,
50 &ecore_con_event_client_error_mp,
51 &ecore_con_event_server_add_mp,
52 &ecore_con_event_server_del_mp,
53 &ecore_con_event_server_write_mp,
54 &ecore_con_event_server_data_mp
55};
56
57void
58ecore_con_mempool_init(void)
59{
60 const char *choice;
61 unsigned int i;
62
63 choice = getenv("EINA_MEMPOOL");
64 if (!choice || !choice[0])
65 choice = "chained_mempool";
66
67 for (i = 0; i < sizeof (mempool_array) / sizeof (mempool_array[0]); ++i)
68 {
69 retry:
70 mempool_array[i]->mp = eina_mempool_add(choice, mempool_array[i]->name, NULL, mempool_array[i]->size, 64);
71 if (!mempool_array[i]->mp)
72 {
73 if (strcmp(choice, "pass_through") != 0)
74 {
75 ERR("Falling back to pass through ! Previously tried '%s' mempool.", choice);
76 choice = "pass_through";
77 goto retry;
78 }
79 else
80 {
81 ERR("Impossible to allocate mempool '%s' !", choice);
82 return ;
83 }
84 }
85 }
86}
87
88void
89ecore_con_mempool_shutdown(void)
90{
91 unsigned int i;
92
93 for (i = 0; i < sizeof (mempool_array) / sizeof (mempool_array[0]); ++i)
94 {
95 eina_mempool_del(mempool_array[i]->mp);
96 mempool_array[i]->mp = NULL;
97 }
98}
99