From: Vsevolod Stakhov Date: Mon, 4 May 2009 15:53:43 +0000 (+0400) Subject: * Fix shared hashes avoiding its resizing X-Git-Tag: 0.2.7~157 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3604753e01e1ab6b9c4a43ea199b1cb466960df6;p=thirdparty%2Frspamd.git * Fix shared hashes avoiding its resizing --- diff --git a/src/hash.c b/src/hash.c index a8309ff36e..ab9830d2d6 100644 --- a/src/hash.c +++ b/src/hash.c @@ -179,12 +179,12 @@ rspamd_hash_new (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_ * Create new hash in specified pool using shared memory */ rspamd_hash_t* -rspamd_hash_new_shared (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func) +rspamd_hash_new_shared (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func, gint size) { rspamd_hash_t* hash; hash = memory_pool_alloc_shared (pool, sizeof (rspamd_hash_t)); - hash->size = HASH_TABLE_MIN_SIZE; + hash->size = size; hash->nnodes = 0; hash->hash_func = hash_func ? hash_func : g_direct_hash; hash->key_equal_func = key_equal_func; @@ -235,9 +235,10 @@ rspamd_hash_insert (rspamd_hash_t *hash, gpointer key, gpointer value) if (hash->shared) { memory_pool_wunlock_rwlock (hash->lock); } - - rspamd_hash_maybe_resize (hash); - + + if (!hash->shared) { + rspamd_hash_maybe_resize (hash); + } } /* diff --git a/src/hash.h b/src/hash.h index 024cb3851a..594b6c63bb 100644 --- a/src/hash.h +++ b/src/hash.h @@ -46,7 +46,7 @@ rspamd_hash_t* rspamd_hash_new (memory_pool_t *pool, GHashFunc hash_func, GEqual * @param key_equal_func pointer to function for comparing keys * @return new rspamd_hash object */ -rspamd_hash_t* rspamd_hash_new_shared (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func); +rspamd_hash_t* rspamd_hash_new_shared (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func, gint size); /** * Insert item in hash diff --git a/src/main.c b/src/main.c index 2b56cd9612..668c0d7cc6 100644 --- a/src/main.c +++ b/src/main.c @@ -575,7 +575,7 @@ main (int argc, char **argv, char **env) rspamd->statfile_pool = statfile_pool_new (cfg->max_statfile_size); /* Init counters */ - counters = rspamd_hash_new_shared (rspamd->server_pool, g_str_hash, g_str_equal); + counters = rspamd_hash_new_shared (rspamd->server_pool, g_str_hash, g_str_equal, 64); for (i = 0; i < cfg->workers_number; i++) { fork_worker (rspamd, listen_sock, TYPE_WORKER); diff --git a/src/statfile.c b/src/statfile.c index e41c1af15c..0081541947 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -110,7 +110,7 @@ statfile_pool_new (size_t max_size) new->pool = memory_pool_new (memory_pool_get_size ()); new->max = max_size; new->files = rspamd_hash_new (new->pool, g_str_hash, g_str_equal); - new->maps = rspamd_hash_new_shared (new->pool, g_str_hash, g_str_equal); + new->maps = rspamd_hash_new_shared (new->pool, g_str_hash, g_str_equal, 64); return new; }