From 228b958489922e08eedfeaf545b4410aafed45da Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 9 Dec 2017 15:54:01 +0000 Subject: [PATCH] [Minor] Avoid double scheduling for maps --- src/libutil/map.c | 7 +++++++ src/libutil/map_private.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libutil/map.c b/src/libutil/map.c index e2874f7e2..0965201a8 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -1053,6 +1053,11 @@ rspamd_map_schedule_periodic (struct rspamd_map *map, gdouble timeout; struct map_periodic_cbdata *cbd; + if (map->scheduled_check) { + /* Do not schedule check if some check is already scheduled */ + return; + } + if (map->next_check != 0) { timeout = map->next_check - rspamd_get_calendar_ticks (); @@ -1098,6 +1103,7 @@ rspamd_map_schedule_periodic (struct rspamd_map *map, cbd->cbdata.cur_data = NULL; cbd->cbdata.map = map; cbd->map = map; + map->scheduled_check = TRUE; REF_INIT_RETAIN (cbd, rspamd_map_periodic_dtor); evtimer_set (&cbd->ev, rspamd_map_periodic_callback, cbd); @@ -1531,6 +1537,7 @@ rspamd_map_periodic_callback (gint fd, short what, void *ud) struct rspamd_map *map; map = cbd->map; + map->scheduled_check = FALSE; if (!cbd->locked) { if (!g_atomic_int_compare_and_exchange (cbd->map->locked, 0, 1)) { diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h index 55641f3dd..fd2098cd1 100644 --- a/src/libutil/map_private.h +++ b/src/libutil/map_private.h @@ -113,6 +113,7 @@ struct rspamd_map { gchar *description; gchar *name; guint32 id; + gboolean scheduled_check; /* Should we check HTTP or just load cached data */ gboolean active_http; struct timeval tv; @@ -142,8 +143,8 @@ struct map_periodic_cbdata { struct event ev; gboolean need_modify; gboolean errored; - guint cur_backend; gboolean locked; + guint cur_backend; ref_entry_t ref; }; -- 2.39.5