From 69eb2e171973c718496197b6e3268e479d825d68 Mon Sep 17 00:00:00 2001 From: xiehan <52160700+Barenboim@users.noreply.github.com> Date: Mon, 13 Jan 2025 21:47:33 +0800 Subject: [PATCH] Use poller threads to handle canceled timer. (#1679) --- src/kernel/poller.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/kernel/poller.c b/src/kernel/poller.c index 60b9d3e785..7359862470 100644 --- a/src/kernel/poller.c +++ b/src/kernel/poller.c @@ -1600,6 +1600,7 @@ int poller_add_timer(const struct timespec *value, void *context, void **timer, int poller_del_timer(void *timer, poller_t *poller) { struct __poller_node *node = (struct __poller_node *)timer; + int stopped = 0; pthread_mutex_lock(&poller->mutex); if (!node->removed) @@ -1610,6 +1611,12 @@ int poller_del_timer(void *timer, poller_t *poller) __poller_tree_erase(node, poller); else list_del(&node->list); + + node->error = 0; + node->state = PR_ST_DELETED; + stopped = poller->stopped; + if (!stopped) + write(poller->pipe_wr, &node, sizeof (void *)); } else { @@ -1618,15 +1625,10 @@ int poller_del_timer(void *timer, poller_t *poller) } pthread_mutex_unlock(&poller->mutex); - if (node) - { - node->error = 0; - node->state = PR_ST_DELETED; + if (stopped) poller->callback((struct poller_result *)node, poller->context); - return 0; - } - return -1; + return -!node; } void poller_stop(poller_t *poller)