aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-05-04 18:55:12 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-05-04 18:55:12 +0400
commit05556b30f9f309abc532f26c86a2e8266c2e72c7 (patch)
tree70007f830b786030de17e38df04754907094bb81 /src/util.c
parente30ea48c912be20ddc9c327205d146e46d60535e (diff)
downloadrspamd-05556b30f9f309abc532f26c86a2e8266c2e72c7.tar.gz
rspamd-05556b30f9f309abc532f26c86a2e8266c2e72c7.zip
* Add counters for rspamd symbols
* Fix shared hashes
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 19afe0611..7d636b843 100644
--- a/src/util.c
+++ b/src/util.c
@@ -29,6 +29,7 @@
#include "main.h"
sig_atomic_t do_reopen_log = 0;
+extern rspamd_hash_t *counters;
int
make_socket_nonblocking (int fd)
@@ -811,6 +812,33 @@ calculate_check_time (struct timespec *begin, int resolution)
return (const char *)res;
}
+void
+set_counter (const char *name, long int value)
+{
+ struct counter_data *cd;
+ double alpha;
+ char *key;
+
+ cd = rspamd_hash_lookup (counters, (gpointer)name);
+
+ if (cd == NULL) {
+ cd = memory_pool_alloc_shared (counters->pool, sizeof (struct counter_data));
+ cd->value = value;
+ cd->number = 1;
+ key = memory_pool_strdup_shared (counters->pool, name);
+ rspamd_hash_insert (counters, (gpointer)key, (gpointer)cd);
+ }
+ else {
+ /* Calculate new value */
+ memory_pool_wlock_rwlock (counters->lock);
+
+ alpha = 2. / (++cd->number + 1);
+ cd->value = cd->value * (1. - alpha) + value * alpha;
+
+ memory_pool_wunlock_rwlock (counters->lock);
+ }
+}
+
/*
* vi:ts=4
*/