commit b3713de: [Fix] Fix pending checks for events
Vsevolod Stakhov
vsevolod at highsecure.ru
Thu Aug 29 12:14:05 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-08-29 13:06:23 +0100
URL: https://github.com/rspamd/rspamd/commit/b3713de7cefa87af9ed95d091db497cef63502d0
[Fix] Fix pending checks for events
---
contrib/libev/ev.h | 2 ++
src/libserver/monitored.c | 2 +-
src/libserver/worker_util.c | 4 ++--
src/libstat/backends/redis_backend.c | 12 ++++++------
src/libutil/libev_helper.c | 6 +++---
src/libutil/upstream.c | 10 +++++-----
6 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/contrib/libev/ev.h b/contrib/libev/ev.h
index b27a2fdad..4b7503d3d 100644
--- a/contrib/libev/ev.h
+++ b/contrib/libev/ev.h
@@ -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)
diff --git a/src/libserver/monitored.c b/src/libserver/monitored.c
index 690acfe7d..4d88bb4f9 100644
--- a/src/libserver/monitored.c
+++ b/src/libserver/monitored.c
@@ -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);
}
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 99f0f9948..511289a2d 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -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);
}
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index 9dd3624fb..fd31d287a 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -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);
}
diff --git a/src/libutil/libev_helper.c b/src/libutil/libev_helper.c
index 81a23dea6..65a53d3f7 100644
--- a/src/libutil/libev_helper.c
+++ b/src/libutil/libev_helper.c
@@ -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);
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index 0b7fd0c2f..177731038 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -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);
}
More information about the Commits
mailing list