aboutsummaryrefslogtreecommitdiffstats
path: root/src/mem_pool.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-05-13 17:07:20 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-05-13 17:07:20 +0400
commit2a45f0daa25c66db449741d9c93a7ea6ef868729 (patch)
tree1140aa892fec576561e614fd10337720ce03a298 /src/mem_pool.c
parentd85518101f1b1363ee965c2b4af595e379f89afe (diff)
downloadrspamd-2a45f0daa25c66db449741d9c93a7ea6ef868729.tar.gz
rspamd-2a45f0daa25c66db449741d9c93a7ea6ef868729.zip
* Fix config reloading
* Add ability to register variables in memory pools (hash with known lifetime) * Avoid of using of some global variables
Diffstat (limited to 'src/mem_pool.c')
-rw-r--r--src/mem_pool.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mem_pool.c b/src/mem_pool.c
index 23907d260..11f74f2f3 100644
--- a/src/mem_pool.c
+++ b/src/mem_pool.c
@@ -148,6 +148,8 @@ memory_pool_new (memory_pool_ssize_t size)
new->shared_pool = NULL;
new->first_pool = new->cur_pool;
new->destructors = NULL;
+ /* Set it upon first call of set variable */
+ new->variables = NULL;
mem_pool_stat->pools_allocated++;
@@ -460,6 +462,9 @@ memory_pool_delete (memory_pool_t * pool)
mem_pool_stat->chunks_freed++;
STAT_UNLOCK ();
}
+ if (pool->variables) {
+ g_hash_table_destroy (pool->variables);
+ }
mem_pool_stat->pools_freed++;
g_slice_free (memory_pool_t, pool);
@@ -570,6 +575,30 @@ memory_pool_wunlock_rwlock (memory_pool_rwlock_t * lock)
memory_pool_unlock_mutex (lock->__w_lock);
}
+void
+memory_pool_set_variable (memory_pool_t *pool, const gchar *name, gpointer value, pool_destruct_func destructor)
+{
+ if (pool->variables == NULL) {
+ pool->variables = g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ g_hash_table_insert (pool->variables, memory_pool_strdup (pool, name), value);
+ if (destructor != NULL) {
+ memory_pool_add_destructor (pool, destructor, value);
+ }
+}
+
+gpointer
+memory_pool_get_variable (memory_pool_t *pool, const gchar *name)
+{
+ if (pool->variables == NULL) {
+ return NULL;
+ }
+
+ return g_hash_table_lookup (pool->variables, name);
+}
+
+
/*
* vi:ts=4
*/