]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
* Fix shared hashes avoiding its resizing
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 4 May 2009 15:53:43 +0000 (19:53 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 4 May 2009 15:53:43 +0000 (19:53 +0400)
src/hash.c
src/hash.h
src/main.c
src/statfile.c

index a8309ff36eb8ff99d5852fb7c22589b00ec68179..ab9830d2d6b41350e951021fe3be40d91b79a521 100644 (file)
@@ -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);
+       }
 }
 
 /* 
index 024cb3851a4f89e22aeea2a704ba22b3f3bb2e49..594b6c63bb3c7e1ded6a814732da7e7bbe47d282 100644 (file)
@@ -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
index 2b56cd96123b5f450b8780e74c47a88c02c4ca40..668c0d7cc6e30b7b668001f4c63f04076e6b27cc 100644 (file)
@@ -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);
index e41c1af15cec6ef6fe81e20bf51c64494e785192..0081541947ed80847b023f7ba1ea44178e18ea4b 100644 (file)
@@ -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;
 }