From 04f6dc10a4f6b6b39520fd3287401e5dbfa81b4c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 14 Jun 2015 14:17:29 -0400 Subject: [PATCH] Use common routine for jittering time values. --- src/fuzzy_storage.c | 3 +-- src/libutil/map.c | 9 +-------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 052cf64c9..f544c4090 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -311,8 +311,7 @@ sync_callback (gint fd, short what, void *arg) evtimer_set (&tev, sync_callback, worker); event_base_set (ctx->ev_base, &tev); /* Plan event with jitter */ - next_check = ctx->sync_timeout * (1. + ((gdouble)ottery_rand_uint32 ()) / - G_MAXUINT32); + next_check = rspamd_time_jitter (ctx->sync_timeout, 0); double_to_tv (next_check, &tmv); evtimer_add (&tev, &tmv); diff --git a/src/libutil/map.c b/src/libutil/map.c index 3fe7495b3..afb31c953 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -285,14 +285,7 @@ jitter_timeout_event (struct rspamd_map *map, gboolean locked, gboolean initial) /* Plan event again with jitter */ evtimer_del (&map->ev); - jittered_sec = timeout; - if (locked) { - /* Add bigger jitter */ - jittered_sec += g_random_double () * timeout * 4; - } - else { - jittered_sec += g_random_double () * timeout; - } + jittered_sec = rspamd_time_jitter (locked ? timeout * 4 : timeout, 0); double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); -- 2.39.5