From 27d1e498b827edc71bb5fb995766deaa26a2fa03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 12 Sep 2022 16:35:55 +0200 Subject: [PATCH] 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. --- lib/isc/include/isc/timer.h | 4 +++- lib/isc/timer.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/isc/include/isc/timer.h b/lib/isc/include/isc/timer.h index 45bc317bbb..0c0cf1a8d6 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 46c2d4b99c..600380997e 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); +}