* eet: Add mempool for Eet_Node structure.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 17 Jan 2010 14:32:58 +0000 (14:32 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 17 Jan 2010 14:32:58 +0000 (14:32 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eet@45259 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/Eet_private.h
src/lib/eet_data.c
src/lib/eet_lib.c
src/lib/eet_node.c

index fbbc6a4..55c5e04 100644 (file)
@@ -136,6 +136,11 @@ Eet_Error eet_identity_sign(FILE *fp, Eet_Key *key);
 void eet_identity_unref(Eet_Key *key);
 void eet_identity_ref(Eet_Key *key);
 
+void eet_node_shutdown(void);
+int eet_node_init(void);
+Eet_Node *eet_node_new(void);
+void eet_node_free(Eet_Node *node);
+
 #ifndef PATH_MAX
 # define PATH_MAX 4096
 #endif
index 8a7f513..bb71ba2 100644 (file)
@@ -2133,7 +2133,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
                                 if (!strcmp(tok4, "{"))
                                   {
                                      /* we have 'group NAM TYP {' */
-                                     n = calloc(1, sizeof(Eet_Node));
+                                     n = eet_node_new();
                                      if (n)
                                        {
                                           n->parent = node;
@@ -2192,7 +2192,7 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
                                 /* we have 'value NAME TYP XXX' */
                                 if (node_base)
                                   {
-                                     n = calloc(1, sizeof(Eet_Node));
+                                     n = eet_node_new();
                                      if (n)
                                        {
                                           n->parent = node;
index 771aa9f..a23acd5 100644 (file)
@@ -773,6 +773,12 @@ eet_init(void)
        goto shutdown_eina;
      }
 
+   if (!eet_node_init())
+     {
+       EINA_LOG_ERR("Eet: Eet_Node mempool creation failed");
+       goto unregister_log_domain;
+     }
+
 #ifdef HAVE_GNUTLS
    /* Before the library can be used, it must initialize itself if needed. */
    if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P) == 0)
@@ -781,7 +787,7 @@ eet_init(void)
        /* Disable warning messages about problems with the secure memory subsystem.
           This command should be run right after gcry_check_version. */
        if (gcry_control(GCRYCTL_DISABLE_SECMEM_WARN))
-         goto unregister_log_domain;
+         goto shutdown_eet;
        /* This command is used to allocate a pool of secure memory and thus
           enabling the use of secure memory. It also drops all extra privileges the
           process has (i.e. if it is run as setuid (root)). If the argument nbytes
@@ -792,7 +798,7 @@ eet_init(void)
          WRN("BIG FAT WARNING: I AM UNABLE TO REQUEST SECMEM, Cryptographic operation are at risk !");
      }
    if (gnutls_global_init())
-     goto unregister_log_domain;
+     goto shutdown_eet;
 #endif
 #ifdef HAVE_OPENSSL
    ERR_load_crypto_strings();
@@ -801,6 +807,8 @@ eet_init(void)
 
    return eet_init_count;
 
+ shutdown_eet:
+   eet_node_shutdown();
  unregister_log_domain:
    eina_log_domain_unregister(_eet_log_dom_global);
    _eet_log_dom_global = -1;
@@ -816,6 +824,7 @@ eet_shutdown(void)
      return eet_init_count;
 
    eet_clearcache();
+   eet_node_shutdown();
 #ifdef HAVE_GNUTLS
    gnutls_global_deinit();
 #endif
index f35f487..3fc6959 100644 (file)
@@ -6,6 +6,7 @@
 # include <config.h>
 #endif
 
+#include <string.h>
 #include <stdio.h>
 
 #include <Eina.h>
 #include "Eet.h"
 #include "Eet_private.h"
 
+static Eina_Mempool *_eet_node_mp = NULL;
+
+Eet_Node *
+eet_node_new(void)
+{
+   Eet_Node *result;
+
+   result = eina_mempool_malloc(_eet_node_mp, sizeof (Eet_Node));
+   if (!result)
+     return NULL;
+
+   memset(result, 0, sizeof (Eet_Node));
+   return result;
+}
+
+void
+eet_node_free(Eet_Node *node)
+{
+   eina_mempool_free(_eet_node_mp, node);
+}
+
 static Eet_Node *
 _eet_node_new(const char *name, int type)
 {
    Eet_Node *n;
 
-   n = calloc(1, sizeof (Eet_Node));
+   n = eet_node_new();
    if (!n) return NULL;
 
    n->type = type;
@@ -317,7 +339,7 @@ eet_node_del(Eet_Node *n)
      }
 
    eina_stringshare_del(n->name);
-   free(n);
+   eet_node_free(n);
 }
 
 static const char *eet_node_dump_g_name[6] = {
@@ -534,3 +556,26 @@ eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const ch
         break;
      }
 }
+
+int
+eet_node_init(void)
+{
+   char *choice;
+   char *tmp;
+
+   choice = "chained_mempool";
+   tmp = getenv("EET_MEMPOOL");
+   if (tmp && tmp[0])
+     choice = tmp;
+
+   _eet_node_mp = eina_mempool_add(choice, "eet-node-alloc", NULL, sizeof(Eet_Node), 1024);
+
+   return _eet_node_mp ? 1 : 0;
+}
+
+void
+eet_node_shutdown(void)
+{
+   eina_mempool_del(_eet_node_mp);
+   _eet_node_mp = NULL;
+}