]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add isc_timer_async_destroy() helper function
authorOndřej Surý <ondrej@isc.org>
Mon, 12 Sep 2022 14:35:55 +0000 (16:35 +0200)
committerEvan Hunt <each@isc.org>
Wed, 21 Sep 2022 21:25:33 +0000 (14:25 -0700)
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
lib/isc/timer.c

index 45bc317bbb7ddf87f583de96a3e57db92befebc5..0c0cf1a8d6a50a1cd67401dbcb953e051a250c85 100644 (file)
@@ -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:
  *
index 46c2d4b99c11a2399d1218b5f6849771bc99d0ec..600380997e3d7fc2169944675826ad62e5f1ccf3 100644 (file)
@@ -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);
+}