From: Ondřej Surý Date: Mon, 12 Sep 2022 14:35:55 +0000 (+0200) Subject: Add isc_timer_async_destroy() helper function X-Git-Tag: v9.19.6~46^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=27d1e498b827edc71bb5fb995766deaa26a2fa03;p=thirdparty%2Fbind9.git Add isc_timer_async_destroy() helper function As it sometimes happens that the object using isc_timer_t is destroyed via detaching all the references with no guarantee that the last thread will be matching thread, add a helper isc_timer_async_destroy() function that stops the timer and runs the destroy function via isc_async_run() on the matching thread. --- diff --git a/lib/isc/include/isc/timer.h b/lib/isc/include/isc/timer.h index 45bc317bbb7..0c0cf1a8d6a 100644 --- a/lib/isc/include/isc/timer.h +++ b/lib/isc/include/isc/timer.h @@ -140,10 +140,12 @@ isc_timer_start(isc_timer_t *timer, isc_timertype_t type, * interval. */ +void +isc_timer_async_destroy(isc_timer_t **timerp); void isc_timer_destroy(isc_timer_t **timerp); /*%< - * Destroy the timer *timerp. + * Destroy (asynchronously) the timer *timerp. * * Requires: * diff --git a/lib/isc/timer.c b/lib/isc/timer.c index 46c2d4b99c1..600380997e3 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -225,3 +225,16 @@ void isc_timer_destroy(isc_timer_t **timerp) { isc__timer_detach(timerp); } + +void +isc_timer_async_destroy(isc_timer_t **timerp) { + isc_timer_t *timer = NULL; + + REQUIRE(timerp != NULL && VALID_TIMER(*timerp)); + + timer = *timerp; + *timerp = NULL; + + isc_timer_stop(timer); + isc_async_run(timer->loop, isc__timer_destroy, timer); +}