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.
This commit is contained in:
Ondřej Surý 2022-09-12 16:35:55 +02:00 committed by Evan Hunt
parent 3a735998bc
commit 27d1e498b8
2 changed files with 16 additions and 1 deletions

View 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:
*

View 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);
}