From 1110e6fc658b395de5569dc98afdae03083c0f5b Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 30 Mar 2023 23:29:45 -0400 Subject: [PATCH] freebsd_network: Migrate callout invocation to another function. Avoids "goto" and reduces indentation. --- src/libs/compat/freebsd_network/callout.cpp | 37 ++++++++++++--------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/libs/compat/freebsd_network/callout.cpp b/src/libs/compat/freebsd_network/callout.cpp index 9e4153efc5..1c6279d82b 100644 --- a/src/libs/compat/freebsd_network/callout.cpp +++ b/src/libs/compat/freebsd_network/callout.cpp @@ -33,6 +33,26 @@ static thread_id sThread; static bigtime_t sTimeout; +static void +invoke_callout(callout *c, struct mtx *c_mtx) +{ + if (c_mtx != NULL) { + mtx_lock(c_mtx); + + if (c->c_due < 0) { + mtx_unlock(c_mtx); + return; + } + c->c_due = -1; + } + + c->c_func(c->c_arg); + + if (c_mtx != NULL && (c->c_flags & CALLOUT_RETURNUNLOCKED) == 0) + mtx_unlock(c_mtx); +} + + static status_t callout_thread(void* /*data*/) { @@ -67,23 +87,8 @@ callout_thread(void* /*data*/) mutex_unlock(&sLock); - if (c_mtx != NULL) { - mtx_lock(c_mtx); + invoke_callout(c, c_mtx); - if (c->c_due < 0) { - mtx_unlock(c_mtx); - goto done; - } - c->c_due = -1; - } - - c->c_func(c->c_arg); - - if (c_mtx != NULL - && (c->c_flags & CALLOUT_RETURNUNLOCKED) == 0) - mtx_unlock(c_mtx); - - done: if ((status = mutex_lock(&sLock)) != B_OK) break;