Skip to content

Commit

Permalink
Add permanent timer, for deleting only. (#1655)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim authored Nov 18, 2024
1 parent 65cdbf3 commit edb8212
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/kernel/poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,12 @@ int poller_add_timer(const struct timespec *value, void *context, void **timer,
{
struct __poller_node *node;

if (value->tv_nsec < 0 || value->tv_nsec >= 1000000000)
{
errno = EINVAL;
return -1;
}

node = (struct __poller_node *)malloc(sizeof (struct __poller_node));
if (node)
{
Expand All @@ -1537,18 +1543,25 @@ int poller_add_timer(const struct timespec *value, void *context, void **timer,
node->removed = 0;
node->res = NULL;

clock_gettime(CLOCK_MONOTONIC, &node->timeout);
node->timeout.tv_sec += value->tv_sec;
node->timeout.tv_nsec += value->tv_nsec;
if (node->timeout.tv_nsec >= 1000000000)
if (value->tv_sec >= 0)
{
node->timeout.tv_nsec -= 1000000000;
node->timeout.tv_sec++;
clock_gettime(CLOCK_MONOTONIC, &node->timeout);
node->timeout.tv_sec += value->tv_sec;
node->timeout.tv_nsec += value->tv_nsec;
if (node->timeout.tv_nsec >= 1000000000)
{
node->timeout.tv_nsec -= 1000000000;
node->timeout.tv_sec++;
}
}

*timer = node;
pthread_mutex_lock(&poller->mutex);
__poller_insert_node(node, poller);
if (value->tv_sec >= 0)
__poller_insert_node(node, poller);
else
list_add_tail(&node->list, &poller->no_timeo_list);

pthread_mutex_unlock(&poller->mutex);
return 0;
}
Expand Down

0 comments on commit edb8212

Please sign in to comment.