* eet: Add mempool for Eet_Node structure.

SVN revision: 45259
This commit is contained in:
Cedric BAIL 2010-01-17 14:32:58 +00:00
parent 258f47f511
commit a61eda93a4
4 changed files with 65 additions and 6 deletions

View 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

View 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;

View 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

View File

@ -6,6 +6,7 @@
# include <config.h>
#endif
#include <string.h>
#include <stdio.h>
#include <Eina.h>
@ -13,12 +14,33 @@
#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;
}