]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix pending checks for events
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Aug 2019 12:06:23 +0000 (13:06 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 29 Aug 2019 12:06:23 +0000 (13:06 +0100)
contrib/libev/ev.h
src/libserver/monitored.c
src/libserver/worker_util.c
src/libstat/backends/redis_backend.c
src/libutil/libev_helper.c
src/libutil/upstream.c

index b27a2fdade3958e475c1193e165df99a1038da98..4b7503d3de79c37a4467a83076b8cb15d9b731f0 100644 (file)
@@ -705,6 +705,8 @@ EV_API_DECL void ev_resume  (EV_P) EV_NOEXCEPT;
 
 #define ev_is_pending(ev)                    (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */
 #define ev_is_active(ev)                     (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */
+#define ev_can_stop(ev)                      (ev_is_pending(ev) || ev_is_active(ev)) /* ro, true when the watcher has been started */
+
 
 #define ev_cb_(ev)                           (ev)->cb /* rw */
 #define ev_cb(ev)                            (memmove (&ev_cb_ (ev), &((ev_watcher *)(ev))->cb, sizeof (ev_cb_ (ev))), (ev)->cb)
index 690acfe7dcbe8f74f11cdddebc485a2940e3596b..4d88bb4f9d1e4a5e4b31617f6dacc7ed1f7a3a96 100644 (file)
@@ -651,7 +651,7 @@ rspamd_monitored_start (struct rspamd_monitored *m)
        jittered = rspamd_time_jitter (m->ctx->monitoring_interval * m->monitoring_mult,
                        0.0);
 
-       if (ev_is_active (&m->periodic)) {
+       if (ev_can_stop (&m->periodic)) {
                ev_timer_stop (m->ctx->event_loop, &m->periodic);
        }
 
index 99f0f994839cf6b7b36cebf031bd95dd11876235..511289a2d3891ae5af22521dd70f233de059ddee 100644 (file)
@@ -399,12 +399,12 @@ rspamd_worker_stop_accept (struct rspamd_worker *worker)
        /* Remove all events */
        DL_FOREACH_SAFE (worker->accept_events, cur, tmp) {
 
-               if (ev_is_active (&cur->accept_ev) || ev_is_pending (&cur->accept_ev)) {
+               if (ev_can_stop (&cur->accept_ev)) {
                        ev_io_stop (cur->event_loop, &cur->accept_ev);
                }
 
 
-               if (ev_is_active (&cur->throttling_ev) || ev_is_pending (&cur->throttling_ev)) {
+               if (ev_can_stop (&cur->throttling_ev)) {
                        ev_timer_stop (cur->event_loop, &cur->throttling_ev);
                }
 
index 9dd3624fb812c3dff999b4d9fb4eb000b7725eca..fd31d287a8a8ef0181f9180230c5c422ec425fe6 100644 (file)
@@ -1021,7 +1021,7 @@ rspamd_redis_fin (gpointer data)
 
        rt->has_event = FALSE;
        /* Stop timeout */
-       if (ev_is_active (&rt->timeout_event)) {
+       if (ev_can_stop (&rt->timeout_event)) {
                ev_timer_stop (rt->task->event_loop, &rt->timeout_event);
        }
 
@@ -1280,7 +1280,7 @@ rspamd_redis_connected (redisAsyncContext *c, gpointer r, gpointer priv)
                                        /* Further is handled by rspamd_redis_processed */
                                        final = FALSE;
                                        /* Restart timeout */
-                                       if (ev_is_active (&rt->timeout_event)) {
+                                       if (ev_can_stop (&rt->timeout_event)) {
                                                rt->timeout_event.repeat = rt->ctx->timeout;
                                                ev_timer_again (task->event_loop, &rt->timeout_event);
                                        }
@@ -1684,7 +1684,7 @@ rspamd_redis_process_tokens (struct rspamd_task *task,
                rt->has_event = TRUE;
                rt->tokens = g_ptr_array_ref (tokens);
 
-               if (ev_is_active (&rt->timeout_event)) {
+               if (ev_can_stop (&rt->timeout_event)) {
                        rt->timeout_event.repeat = rt->ctx->timeout;
                        ev_timer_again (task->event_loop, &rt->timeout_event);
                }
@@ -1706,7 +1706,7 @@ rspamd_redis_finalize_process (struct rspamd_task *task, gpointer runtime,
        struct redis_stat_runtime *rt = REDIS_RUNTIME (runtime);
        redisAsyncContext *redis;
 
-       if (ev_is_active (&rt->timeout_event)) {
+       if (ev_can_stop (&rt->timeout_event)) {
                ev_timer_stop (task->event_loop, &rt->timeout_event);
        }
 
@@ -1889,7 +1889,7 @@ rspamd_redis_learn_tokens (struct rspamd_task *task, GPtrArray *tokens,
                rt->has_event = TRUE;
 
                /* Set timeout */
-               if (ev_is_active (&rt->timeout_event)) {
+               if (ev_can_stop (&rt->timeout_event)) {
                        rt->timeout_event.repeat = rt->ctx->timeout;
                        ev_timer_again (task->event_loop, &rt->timeout_event);
                }
@@ -1917,7 +1917,7 @@ rspamd_redis_finalize_learn (struct rspamd_task *task, gpointer runtime,
        struct redis_stat_runtime *rt = REDIS_RUNTIME (runtime);
        redisAsyncContext *redis;
 
-       if (ev_is_active (&rt->timeout_event)) {
+       if (ev_can_stop (&rt->timeout_event)) {
                ev_timer_stop (task->event_loop, &rt->timeout_event);
        }
 
index 81a23dea619b7c1b479830d554eb47c2a632d1a9..65a53d3f773d34fe39ba0233fcabca5859ee2f1a 100644 (file)
@@ -80,7 +80,7 @@ void
 rspamd_ev_watcher_stop (struct ev_loop *loop,
                                                struct rspamd_io_ev *ev)
 {
-       if (ev_is_pending (&ev->io) || ev_is_active (&ev->io)) {
+       if (ev_can_stop (&ev->io)) {
                ev_io_stop (EV_A_ &ev->io);
        }
 
@@ -96,7 +96,7 @@ rspamd_ev_watcher_reschedule (struct ev_loop *loop,
 {
        g_assert (ev->cb != NULL);
 
-       if (ev_is_pending (&ev->io) || ev_is_active (&ev->io)) {
+       if (ev_can_stop (&ev->io)) {
                ev_io_stop (EV_A_ &ev->io);
                ev_io_set (&ev->io, ev->io.fd, what);
                ev_io_start (EV_A_ &ev->io);
@@ -108,7 +108,7 @@ rspamd_ev_watcher_reschedule (struct ev_loop *loop,
        }
 
        if (ev->timeout > 0) {
-               if (!(ev_is_active (&ev->tm) || ev_is_pending (&ev->tm))) {
+               if (!(ev_can_stop (&ev->tm))) {
                        ev->tm.data = ev;
                        ev_timer_init (&ev->tm, rspamd_ev_watcher_timer_cb, ev->timeout, 0.0);
                        ev_timer_start (EV_A_ &ev->tm);
index 0b7fd0c2fca326698f3303fe83e0a354787b00dc..17773103868eba2c6620ace3ec3c994d3931bcf9 100644 (file)
@@ -172,7 +172,7 @@ rspamd_upstreams_library_config (struct rspamd_config *cfg,
 
                while (cur) {
                        upstream = cur->data;
-                       if (!ev_is_active (&upstream->ev) && upstream->ls &&
+                       if (!ev_can_stop (&upstream->ev) && upstream->ls &&
                                                !(upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) {
                                gdouble when = rspamd_time_jitter (upstream->ls->limits.lazy_resolve_time,
                                                upstream->ls->limits.lazy_resolve_time * .1);
@@ -281,7 +281,7 @@ rspamd_upstream_set_active (struct upstream_list *ls, struct upstream *upstream)
        if (upstream->ctx && upstream->ctx->configured &&
                !(upstream->flags & RSPAMD_UPSTREAM_FLAG_NORESOLVE)) {
 
-               if (ev_is_active (&upstream->ev)) {
+               if (ev_can_stop (&upstream->ev)) {
                        ev_timer_stop (upstream->ctx->event_loop, &upstream->ev);
                }
                /* Start lazy names resolution */
@@ -525,7 +525,7 @@ rspamd_upstream_set_inactive (struct upstream_list *ls, struct upstream *upstrea
                ntim = rspamd_time_jitter (ls->limits.revive_time,
                                ls->limits.revive_jitter);
 
-               if (ev_is_active (&upstream->ev)) {
+               if (ev_can_stop (&upstream->ev)) {
                        ev_timer_stop (upstream->ctx->event_loop, &upstream->ev);
                }
 
@@ -721,7 +721,7 @@ rspamd_upstream_dtor (struct upstream *up)
 
        if (up->ctx) {
 
-               if (ev_is_active (&up->ev)) {
+               if (ev_can_stop (&up->ev)) {
                        ev_timer_stop (up->ctx->event_loop, &up->ev);
                }
 
@@ -1030,7 +1030,7 @@ rspamd_upstream_restore_cb (gpointer elt, gpointer ls)
        /* Here the upstreams list is already locked */
        RSPAMD_UPSTREAM_LOCK (up->lock);
 
-       if (ev_is_active (&up->ev)) {
+       if (ev_can_stop (&up->ev)) {
                ev_timer_stop (up->ctx->event_loop, &up->ev);
        }