From: Vsevolod Stakhov Date: Sun, 14 Jun 2015 18:17:29 +0000 (-0400) Subject: Use common routine for jittering time values. X-Git-Tag: 1.0.0~542 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=04f6dc10a4f6b6b39520fd3287401e5dbfa81b4c;p=rspamd.git Use common routine for jittering time values. --- 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);