ecore: improve ecore_con speed by using mempool.
authorCedric BAIL <cedric.bail@free.fr>
Sun, 6 Nov 2011 12:26:00 +0000 (12:26 +0000)
committerCedric BAIL <cedric.bail@free.fr>
Sun, 6 Nov 2011 12:26:00 +0000 (12:26 +0000)
SVN revision: 64814

legacy/ecore/src/examples/Makefile.am
legacy/ecore/src/examples/client_bench.c [deleted file]
legacy/ecore/src/examples/ecore_client_bench.c [new file with mode: 0644]
legacy/ecore/src/examples/ecore_server_bench.c [new file with mode: 0644]
legacy/ecore/src/examples/server_bench.c [deleted file]
legacy/ecore/src/lib/ecore_con/Makefile.am
legacy/ecore/src/lib/ecore_con/ecore_con.c
legacy/ecore/src/lib/ecore_con/ecore_con_alloc.c [new file with mode: 0644]
legacy/ecore/src/lib/ecore_con/ecore_con_private.h

index 282adce5ea7f1770c438a2424043379b4795975f..63748a58bbdc019c41280444dc5f421d218eb4de 100644 (file)
@@ -39,8 +39,8 @@ SRCS = \
        ecore_con_server_simple_example.c \
        ecore_con_server_http_example.c \
        ecore_con_client_simple_example.c \
-       client_bench.c \
-       server_bench.c \
+       ecore_client_bench.c \
+       ecore_server_bench.c \
        ecore_con_client_example.c \
        ecore_con_server_example.c \
        ecore_fd_handler_gnutls_example.c \
@@ -91,7 +91,9 @@ pkglib_PROGRAMS += \
        ecore_evas_basics_example \
        ecore_evas_buffer_example_01 \
        ecore_evas_buffer_example_02 \
-       ecore_evas_ews_example
+       ecore_evas_ews_example \
+       ecore_client_bench \
+       ecore_server_bench
 
 ecore_con_lookup_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la
 ecore_con_url_headers_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la
@@ -103,5 +105,7 @@ ecore_con_client_simple_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/li
 ecore_evas_window_sizes_example_LDADD = $(ECOREBASELDADD) @EVAS_LIBS@ $(top_builddir)/src/lib/ecore_evas/libecore_evas.la
 ecore_evas_buffer_example_01_LDADD = $(ECOREBASELDADD) @EVAS_LIBS@ $(top_builddir)/src/lib/ecore_evas/libecore_evas.la
 ecore_evas_buffer_example_02_LDADD = $(ECOREBASELDADD) @EVAS_LIBS@ $(top_builddir)/src/lib/ecore_evas/libecore_evas.la
+ecore_client_bench_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la
+ecore_server_bench_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la
 
 endif
diff --git a/legacy/ecore/src/examples/client_bench.c b/legacy/ecore/src/examples/client_bench.c
deleted file mode 100644 (file)
index 93a0fb1..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <stdio.h>
-#include <Ecore.h>
-#include <Ecore_Con.h>
-
-/* Ecore_Con client example
- * 2010 Mike Blumenkrantz
- */
-
-#define NUM_CLIENTS 10000
-
-static Eina_Counter *counter;
-static int add = 0;
-static int del = 0;
-
-Eina_Bool
-_add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
-{
-   ++add;
-   printf("Connection #%i!\n", add);
-   if (add == NUM_CLIENTS)
-     ecore_main_loop_quit();
-
-   return ECORE_CALLBACK_RENEW;
-}
-
-Eina_Bool
-_del(void *data, int type, Ecore_Con_Event_Server_Add *ev)
-{
-   ++del;
-   printf("Connection lost! #%i!\n", del);
-
-   return ECORE_CALLBACK_RENEW;
-}
-
-static void
-_spawn(void *data)
-{
-   int x;
-   
-   for (x = 0; x < NUM_CLIENTS; x++)
-     {
-//        printf("Creating connection %i\n", x);
-        if (!ecore_con_server_connect(ECORE_CON_REMOTE_NODELAY, "127.0.0.1", 8080, NULL))
-          {
-             printf("CRITICAL ERROR!\n"
-                    "Could not create connection #%i!\n", x);
-             exit(1);
-          }
-     }
-     printf("***Job done***\n");
-}
-
-int main(void)
-{
-   double done;
-   eina_init();
-   ecore_init();
-   ecore_con_init();
-
-   eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR);
-   eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR);
-   counter = eina_counter_new("client");
-   eina_counter_start(counter);
-   done = ecore_time_get();
-
-   ecore_job_add(_spawn, NULL);
-
-/* set event handler for server connect */
-   ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
-   ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_del, NULL);
-
-/* start client */
-   ecore_main_loop_begin();
-   eina_counter_stop(counter, 1);
-   printf("\nTime elapsed for %i connections: %f seconds\n%s", NUM_CLIENTS, ecore_time_get() - done, eina_counter_dump(counter));
-   return 0;
-}
diff --git a/legacy/ecore/src/examples/ecore_client_bench.c b/legacy/ecore/src/examples/ecore_client_bench.c
new file mode 100644 (file)
index 0000000..2a58dcf
--- /dev/null
@@ -0,0 +1,77 @@
+#include <stdio.h>
+#include <Ecore.h>
+#include <Ecore_Con.h>
+
+/* Ecore_Con client example
+ * 2010 Mike Blumenkrantz
+ */
+
+#define NUM_CLIENTS 30000
+
+static Eina_Counter *counter;
+static int add = 0;
+static int del = 0;
+
+Eina_Bool
+_add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
+{
+   ++add;
+   printf("Connection #%i!\n", add);
+   if (add == NUM_CLIENTS)
+     ecore_main_loop_quit();
+
+   return ECORE_CALLBACK_RENEW;
+}
+
+Eina_Bool
+_del(void *data, int type, Ecore_Con_Event_Server_Add *ev)
+{
+   ++del;
+   printf("Connection lost! #%i!\n", del);
+
+   return ECORE_CALLBACK_RENEW;
+}
+
+static void
+_spawn(void *data)
+{
+   int x;
+   
+   for (x = 0; x < NUM_CLIENTS; x++)
+     {
+//        printf("Creating connection %i\n", x);
+        if (!ecore_con_server_connect(ECORE_CON_REMOTE_NODELAY, "127.0.0.1", 8080, NULL))
+          {
+             printf("CRITICAL ERROR!\n"
+                    "Could not create connection #%i!\n", x);
+             exit(1);
+          }
+     }
+     printf("***Job done***\n");
+}
+
+int main(void)
+{
+   double done;
+   eina_init();
+   ecore_init();
+   ecore_con_init();
+
+   eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR);
+   eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR);
+   counter = eina_counter_new("client");
+   eina_counter_start(counter);
+   done = ecore_time_get();
+
+   ecore_job_add(_spawn, NULL);
+
+/* set event handler for server connect */
+   ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
+   ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_del, NULL);
+
+/* start client */
+   ecore_main_loop_begin();
+   eina_counter_stop(counter, 1);
+   printf("\nTime elapsed for %i connections: %f seconds\n%s", NUM_CLIENTS, ecore_time_get() - done, eina_counter_dump(counter));
+   return 0;
+}
diff --git a/legacy/ecore/src/examples/ecore_server_bench.c b/legacy/ecore/src/examples/ecore_server_bench.c
new file mode 100644 (file)
index 0000000..db0020c
--- /dev/null
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <Ecore.h>
+#include <Ecore_Con.h>
+
+/* Ecore_Con server example
+ * 2010 Mike Blumenkrantz
+ */
+
+static Ecore_Con_Server *svr;
+static int add;
+static int del;
+
+Eina_Bool
+_add(void *data, int type, Ecore_Con_Event_Client_Add *ev)
+{
+   ++add;
+//   printf ("%s ", ecore_con_client_ip_get(ev->client));
+   printf("Client #%i!\n", add);
+   return ECORE_CALLBACK_RENEW;
+}
+
+Eina_Bool
+_del(void *data, int type, Ecore_Con_Event_Client_Del *ev)
+{
+   ++del;
+   printf("Disconnected #%i!\n", del);
+   if (add == del)
+     ecore_main_loop_quit();
+   return ECORE_CALLBACK_RENEW;
+}
+
+int main(int argc, const char *argv[])
+{
+   ecore_init();
+   ecore_con_init();
+   ecore_app_args_set(argc, argv);
+   eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR);
+   eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR);
+
+
+/* to use a PEM certificate with TLS and SSL3, uncomment the lines below */
+//   if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT, "127.0.0.1", 8080, NULL)))
+
+/* to use simple tcp with ssl/tls, use this line */
+   svr = ecore_con_server_add(ECORE_CON_REMOTE_NODELAY , "127.0.0.1", 8080, NULL);
+   if (!svr)
+     exit(1);
+     
+   ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
+   ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
+
+/* start server */
+   ecore_main_loop_begin();
+   if (add && del)
+     {
+        printf("Restarting server after %i connections\n", add);
+        add = del = 0;
+        ecore_con_server_del(svr);
+        ecore_app_restart();
+     }
+   return 0;
+}
diff --git a/legacy/ecore/src/examples/server_bench.c b/legacy/ecore/src/examples/server_bench.c
deleted file mode 100644 (file)
index db0020c..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <stdio.h>
-#include <Ecore.h>
-#include <Ecore_Con.h>
-
-/* Ecore_Con server example
- * 2010 Mike Blumenkrantz
- */
-
-static Ecore_Con_Server *svr;
-static int add;
-static int del;
-
-Eina_Bool
-_add(void *data, int type, Ecore_Con_Event_Client_Add *ev)
-{
-   ++add;
-//   printf ("%s ", ecore_con_client_ip_get(ev->client));
-   printf("Client #%i!\n", add);
-   return ECORE_CALLBACK_RENEW;
-}
-
-Eina_Bool
-_del(void *data, int type, Ecore_Con_Event_Client_Del *ev)
-{
-   ++del;
-   printf("Disconnected #%i!\n", del);
-   if (add == del)
-     ecore_main_loop_quit();
-   return ECORE_CALLBACK_RENEW;
-}
-
-int main(int argc, const char *argv[])
-{
-   ecore_init();
-   ecore_con_init();
-   ecore_app_args_set(argc, argv);
-   eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR);
-   eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR);
-
-
-/* to use a PEM certificate with TLS and SSL3, uncomment the lines below */
-//   if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT, "127.0.0.1", 8080, NULL)))
-
-/* to use simple tcp with ssl/tls, use this line */
-   svr = ecore_con_server_add(ECORE_CON_REMOTE_NODELAY , "127.0.0.1", 8080, NULL);
-   if (!svr)
-     exit(1);
-     
-   ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
-   ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
-
-/* start server */
-   ecore_main_loop_begin();
-   if (add && del)
-     {
-        printf("Restarting server after %i connections\n", add);
-        add = del = 0;
-        ecore_con_server_del(svr);
-        ecore_app_restart();
-     }
-   return 0;
-}
index 128c47cb0111ea910dc96830dfa351c186556495..300586dd10ae83a746f63e3389fbb91285fee4a7 100644 (file)
@@ -20,7 +20,8 @@ includesdir = $(includedir)/ecore-@VMAJ@
 libecore_con_la_SOURCES = \
 ecore_con.c \
 ecore_con_ssl.c \
-ecore_con_url.c
+ecore_con_url.c \
+ecore_con_alloc.c
 
 if ECORE_HAVE_WIN32
 libecore_con_la_SOURCES += ecore_con_local_win32.c
index aca8ee5ceba139b3c775d8e71fbc0b055bcc3eb2..b731e2ed2d528466e2f491fe14e260618d0536df 100644 (file)
@@ -143,6 +143,8 @@ ecore_con_init(void)
         return --_ecore_con_init_count;
      }
 
+   ecore_con_mempool_init();
+
    ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
    ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
    ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
@@ -178,6 +180,8 @@ ecore_con_shutdown(void)
    EINA_LIST_FOREACH_SAFE(servers, l, l2, svr)
      _ecore_con_server_free(svr);
 
+   ecore_con_mempool_shutdown();
+
    ecore_con_info_shutdown();
    ecore_con_ssl_shutdown();
    eina_log_domain_unregister(_ecore_con_log_dom);
@@ -932,7 +936,7 @@ ecore_con_event_server_add(Ecore_Con_Server *svr)
     Ecore_Con_Event_Server_Add *e;
     int ev = ECORE_CON_EVENT_SERVER_ADD;
 
-    e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
+    e = ecore_con_event_server_add_alloc();
     EINA_SAFETY_ON_NULL_RETURN(e);
 
     svr->event_count++;
@@ -948,7 +952,7 @@ ecore_con_event_server_del(Ecore_Con_Server *svr)
 {
     Ecore_Con_Event_Server_Del *e;
 
-    e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
+    e = ecore_con_event_server_del_alloc();
     EINA_SAFETY_ON_NULL_RETURN(e);
 
     svr->event_count++;
@@ -963,7 +967,7 @@ ecore_con_event_server_write(Ecore_Con_Server *svr, int num)
 {
    Ecore_Con_Event_Server_Write *e;
 
-   e = malloc(sizeof(Ecore_Con_Event_Server_Write));
+   e = ecore_con_event_server_write_alloc();
    EINA_SAFETY_ON_NULL_RETURN(e);
 
    svr->event_count++;
@@ -979,7 +983,7 @@ ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num,
 {
    Ecore_Con_Event_Server_Data *e;
 
-   e = malloc(sizeof(Ecore_Con_Event_Server_Data));
+   e = ecore_con_event_server_data_alloc();
    EINA_SAFETY_ON_NULL_RETURN(e);
 
    svr->event_count++;
@@ -990,8 +994,8 @@ ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num,
         e->data = malloc(num);
         if (!e->data)
           {
-             ERR("alloc!");
-             free(e);
+             ERR("server data allocation failure !");
+             _ecore_con_event_server_data_free(NULL, e);
              return;
           }
         memcpy(e->data, buf, num);
@@ -1009,7 +1013,7 @@ ecore_con_event_client_add(Ecore_Con_Client *cl)
    Ecore_Con_Event_Client_Add *e;
    int ev = ECORE_CON_EVENT_CLIENT_ADD;
 
-   e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
+   e = ecore_con_event_client_add_alloc();
    EINA_SAFETY_ON_NULL_RETURN(e);
 
    cl->event_count++;
@@ -1027,7 +1031,7 @@ ecore_con_event_client_del(Ecore_Con_Client *cl)
 {
     Ecore_Con_Event_Client_Del *e;
 
-    e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
+    e = ecore_con_event_client_del_alloc();
     EINA_SAFETY_ON_NULL_RETURN(e);
 
     if (cl)
@@ -1045,7 +1049,8 @@ void
 ecore_con_event_client_write(Ecore_Con_Client *cl, int num)
 {
    Ecore_Con_Event_Client_Write *e;
-   e = malloc(sizeof(Ecore_Con_Event_Client_Write));
+
+   e = ecore_con_event_client_write_alloc();
    EINA_SAFETY_ON_NULL_RETURN(e);
 
    cl->host_server->event_count++;
@@ -1060,7 +1065,8 @@ void
 ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate)
 {
    Ecore_Con_Event_Client_Data *e;
-   e = malloc(sizeof(Ecore_Con_Event_Client_Data));
+
+   e = ecore_con_event_client_data_alloc();
    EINA_SAFETY_ON_NULL_RETURN(e);
 
    cl->host_server->event_count++;
@@ -1072,8 +1078,8 @@ ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, E
         e->data = malloc(num);
         if (!e->data)
           {
-             free(cl->client_addr);
-             free(cl);
+             ERR("client data allocation failure !");
+             _ecore_con_event_client_data_free(cl->host_server, e);
              return;
           }
         memcpy(e->data, buf, num);
@@ -1097,7 +1103,7 @@ ecore_con_event_server_error(Ecore_Con_Server *svr, const char *error)
 {
    Ecore_Con_Event_Server_Error *e;
 
-   e = calloc(1, sizeof(Ecore_Con_Event_Server_Error));
+   e = ecore_con_event_server_error_alloc();
    EINA_SAFETY_ON_NULL_RETURN(e);
 
    e->server = svr;
@@ -1112,7 +1118,7 @@ ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error)
 {
    Ecore_Con_Event_Client_Error *e;
 
-   e = calloc(1, sizeof(Ecore_Con_Event_Client_Error));
+   e = ecore_con_event_client_error_alloc();
    EINA_SAFETY_ON_NULL_RETURN(e);
 
    e->client = cl;
@@ -2348,7 +2354,7 @@ _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
    if ((svr->event_count <= 0) && (svr->delete_me))
      _ecore_con_server_free(svr);
 
-   free(e);
+   ecore_con_event_client_add_free(e);
 }
 
 static void
@@ -2367,7 +2373,7 @@ _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
    if ((svr->event_count <= 0) && (svr->delete_me))
      _ecore_con_server_free(svr);
 
-   free(e);
+   ecore_con_event_client_del_free(e);
 }
 
 static void
@@ -2385,7 +2391,7 @@ _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
    if ((svr->event_count <= 0) && (svr->delete_me))
      _ecore_con_server_free(svr);
 
-   free(e);
+   ecore_con_event_client_write_free(e);
 }
 
 static void
@@ -2408,7 +2414,7 @@ _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
    if ((svr->event_count <= 0) && (svr->delete_me))
      _ecore_con_server_free(svr);
 
-   free(e);
+   ecore_con_event_client_data_free(e);
 }
 
 static void
@@ -2422,7 +2428,7 @@ _ecore_con_event_server_add_free(void *data __UNUSED__,
    if ((e->server->event_count <= 0) && (e->server->delete_me))
      _ecore_con_server_free(e->server);
 
-   free(e);
+   ecore_con_event_server_add_free(e);
 }
 
 static void
@@ -2436,7 +2442,7 @@ _ecore_con_event_server_del_free(void *data __UNUSED__,
    if ((e->server->event_count <= 0) && (e->server->delete_me))
      _ecore_con_server_free(e->server);
 
-   free(e);
+   ecore_con_event_server_del_free(e);
 }
 
 static void
@@ -2448,7 +2454,7 @@ _ecore_con_event_server_write_free(void *data __UNUSED__,
    if ((e->server->event_count <= 0) && (e->server->delete_me))
      _ecore_con_server_free(e->server);
 
-   free(e);
+   ecore_con_event_server_write_free(e);
 }
 
 static void
@@ -2465,7 +2471,7 @@ _ecore_con_event_server_data_free(void *data __UNUSED__,
    if ((e->server->event_count <= 0) && (e->server->delete_me))
      _ecore_con_server_free(e->server);
 
-   free(e);
+   ecore_con_event_server_data_free(e);
 }
 
 
@@ -2476,7 +2482,8 @@ _ecore_con_event_server_error_free(void *data __UNUSED__, Ecore_Con_Event_Server
    if ((e->server->event_count <= 0) && (e->server->delete_me))
      _ecore_con_server_free(e->server);
    if (e->error) free(e->error);
-   free(e);
+
+   ecore_con_event_server_error_free(e);
 }
 
 static void
@@ -2489,8 +2496,8 @@ _ecore_con_event_client_error_free(Ecore_Con_Server *svr, Ecore_Con_Event_Client
    if ((svr->event_count <= 0) && (svr->delete_me))
      _ecore_con_server_free(svr);
    if (e->error) free(e->error);
-   free(e);
 
+   ecore_con_event_client_error_free(e);
 }
 
 static void
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_alloc.c b/legacy/ecore/src/lib/ecore_con/ecore_con_alloc.c
new file mode 100644 (file)
index 0000000..341c839
--- /dev/null
@@ -0,0 +1,99 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "Ecore.h"
+#include "ecore_private.h"
+#include "Ecore_Con.h"
+#include "ecore_con_private.h"
+
+typedef struct _Ecore_Con_Mempool Ecore_Con_Mempool;
+struct _Ecore_Con_Mempool
+{
+   const char *name;
+   Eina_Mempool *mp;
+   size_t size;
+};
+
+#define GENERIC_ALLOC_FREE(TYPE, Type)                                  \
+  Ecore_Con_Mempool Type##_mp = { #TYPE,  NULL, sizeof (TYPE) };        \
+                                                                        \
+  TYPE *                                                                \
+  Type##_alloc(void)                                                    \
+  {                                                                     \
+     return eina_mempool_malloc(Type##_mp.mp, sizeof (TYPE));           \
+  }                                                                     \
+                                                                        \
+  void                                                                  \
+  Type##_free(TYPE *e)                                                  \
+  {                                                                     \
+     eina_mempool_free(Type##_mp.mp, e);                                \
+  }
+
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Add, ecore_con_event_client_add);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Del, ecore_con_event_client_del);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Write, ecore_con_event_client_write);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Data, ecore_con_event_client_data);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Error, ecore_con_event_server_error);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Client_Error, ecore_con_event_client_error);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Add, ecore_con_event_server_add);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Del, ecore_con_event_server_del);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Write, ecore_con_event_server_write);
+GENERIC_ALLOC_FREE(Ecore_Con_Event_Server_Data, ecore_con_event_server_data);
+
+static Ecore_Con_Mempool *mempool_array[] = {
+  &ecore_con_event_client_add_mp,
+  &ecore_con_event_client_del_mp,
+  &ecore_con_event_client_write_mp,
+  &ecore_con_event_client_data_mp,
+  &ecore_con_event_server_error_mp,
+  &ecore_con_event_client_error_mp,
+  &ecore_con_event_server_add_mp,
+  &ecore_con_event_server_del_mp,
+  &ecore_con_event_server_write_mp,
+  &ecore_con_event_server_data_mp
+};
+
+void
+ecore_con_mempool_init(void)
+{
+   const char *choice;
+   unsigned int i;
+
+   choice = getenv("EINA_MEMPOOL");
+   if (!choice || choice[0])
+     choice = "chained_mempool";
+
+   for (i = 0; i < sizeof (mempool_array) / sizeof (mempool_array[0]); ++i)
+     {
+     retry:
+        mempool_array[i]->mp = eina_mempool_add(choice, mempool_array[i]->name, NULL, mempool_array[i]->size, 64);
+        if (!mempool_array[i]->mp)
+          {
+             if (strcmp(choice, "pass_through") != 0)
+               {
+                  ERR("Falling back to pass through ! Previously tried '%s' mempool.", choice);
+                  choice = "pass_through";
+                  goto retry;
+               }
+             else
+               {
+                  ERR("Impossible to allocate mempool '%s' !", choice);
+                  return ;
+               }
+          }
+     }
+}
+
+void
+ecore_con_mempool_shutdown(void)
+{
+   unsigned int i;
+
+   for (i = 0; i < sizeof (mempool_array) / sizeof (mempool_array[0]); ++i)
+     {
+        eina_mempool_del(mempool_array[i]->mp);
+        mempool_array[i]->mp = NULL;
+     }
+}
+
index 908f2791711e90a4567ac50e4a10dc64ef1d0710..0179992d2d3d5a2b9bb6c9a92637de2c11ed375b 100644 (file)
@@ -298,5 +298,24 @@ int                 ecore_con_info_get(Ecore_Con_Server *svr,
                                        struct addrinfo *hints);
 
 
+#define GENERIC_ALLOC_FREE_HEADER(TYPE, Type) \
+  TYPE *Type##_alloc(void);                  \
+  void Type##_free(TYPE *e);
+
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Add, ecore_con_event_client_add);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Del, ecore_con_event_client_del);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Write, ecore_con_event_client_write);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Data, ecore_con_event_client_data);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Error, ecore_con_event_server_error);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Client_Error, ecore_con_event_client_error);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Add, ecore_con_event_server_add);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Del, ecore_con_event_server_del);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Write, ecore_con_event_server_write);
+GENERIC_ALLOC_FREE_HEADER(Ecore_Con_Event_Server_Data, ecore_con_event_server_data);
+
+void ecore_con_mempool_init(void);
+void ecore_con_mempool_shutdown(void);
+
+#undef GENERIC_ALLOC_FREE_HEADER
 
 #endif