Skip to content

Commit

Permalink
Use poller threads to handle canceled timer. (#1679)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim authored Jan 13, 2025
1 parent 8cb8935 commit 69eb2e1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/kernel/poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
{
Expand All @@ -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)
Expand Down

0 comments on commit 69eb2e1

Please sign in to comment.