From 90d34dcaf0e7ed8a2d96a23ad968e7c8183d25c9 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 24 Mar 2023 11:34:34 -0400 Subject: [PATCH] freebsd_network: Rework callout_stop implementation. From the FreeBSD manual pages: > If the callout is currently being serviced and cannot be stopped, > and at the same time a next invocation of the same callout is also > scheduled, then callout_stop() unschedules the next run and returns > zero. Previously we would return zero but not unschedule the next run. This may fix #18315. --- src/libs/compat/freebsd_network/callout.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libs/compat/freebsd_network/callout.cpp b/src/libs/compat/freebsd_network/callout.cpp index 303a98ebeb..5f6851a2e3 100644 --- a/src/libs/compat/freebsd_network/callout.cpp +++ b/src/libs/compat/freebsd_network/callout.cpp @@ -1,6 +1,6 @@ /* * Copyright 2010, Axel Dörfler, axeld@pinc-software.de. - * Copyright 2018, Haiku, Inc. All rights reserved. + * Copyright 2018-2023, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT license. */ @@ -218,22 +218,24 @@ _callout_stop_safe(struct callout *c, int safe) MutexLocker locker(sLock); + int ret = -1; if (callout_active(c)) { if (safe) { locker.Unlock(); while (callout_active(c)) snooze(100); + locker.Lock(); } - return 0; + ret = 0; } if (c->c_due <= 0) - return -1; + return ret; // this timer is scheduled, cancel it list_remove_item(&sTimers, c); c->c_due = 0; - return 1; + return (ret == -1) ? 1 : ret; }