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();
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);
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++;
{
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++;
{
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++;
{
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++;
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);
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++;
{
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)
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++;
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++;
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);
{
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;
{
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;
if ((svr->event_count <= 0) && (svr->delete_me))
_ecore_con_server_free(svr);
- free(e);
+ ecore_con_event_client_add_free(e);
}
static void
if ((svr->event_count <= 0) && (svr->delete_me))
_ecore_con_server_free(svr);
- free(e);
+ ecore_con_event_client_del_free(e);
}
static void
if ((svr->event_count <= 0) && (svr->delete_me))
_ecore_con_server_free(svr);
- free(e);
+ ecore_con_event_client_write_free(e);
}
static void
if ((svr->event_count <= 0) && (svr->delete_me))
_ecore_con_server_free(svr);
- free(e);
+ ecore_con_event_client_data_free(e);
}
static void
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
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
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
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);
}
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
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
--- /dev/null
+#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;
+ }
+}
+
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