From 673bc1087ffabb2773132f3b4b1223c719a31942 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 30 Mar 2023 17:30:00 -0400 Subject: [PATCH] freebsd_network: Always unset c_due after removing the callout from the list. Use 0 as the magic value instead of a positive one. This way, <= 0 consistently signals that the callout is not in the list, whereas > 0 signals that it is. --- src/libs/compat/freebsd_network/callout.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/compat/freebsd_network/callout.cpp b/src/libs/compat/freebsd_network/callout.cpp index 941ee00aad..9e4153efc5 100644 --- a/src/libs/compat/freebsd_network/callout.cpp +++ b/src/libs/compat/freebsd_network/callout.cpp @@ -62,8 +62,7 @@ callout_thread(void* /*data*/) // execute timer list_remove_item(&sTimers, c); struct mtx *c_mtx = c->c_mtx; - if (c_mtx == NULL) - c->c_due = -1; + c->c_due = 0; sCurrentCallout = c; mutex_unlock(&sLock); @@ -230,10 +229,10 @@ _callout_stop_safe(struct callout *c, int safe) int ret = -1; if (callout_active(c)) { ret = 0; - if (!safe && c->c_mtx != NULL && c->c_due > 0) { + if (!safe && c->c_mtx != NULL && c->c_due == 0) { mtx_assert(c->c_mtx, MA_OWNED); - // The callout is active, but c_due > 0 and we hold the locks: this + // The callout is active, but c_due == 0 and we hold the locks: this // means the callout thread has dequeued it and is waiting for c_mtx. // Clear c_due to signal the callout thread. c->c_due = -1;