Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check node 'removed' flag before next read. #1670

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/kernel/poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ static inline int __poller_create_pfd()
return epoll_create(1);
}

static inline int __poller_close_pfd(int fd)
{
return close(fd);
}

static inline int __poller_add_fd(int fd, int event, void *data,
poller_t *poller)
{
Expand Down Expand Up @@ -171,6 +176,11 @@ static inline int __poller_create_pfd()
return kqueue();
}

static inline int __poller_close_pfd(int fd)
{
return close(fd);
}

static inline int __poller_add_fd(int fd, int event, void *data,
poller_t *poller)
{
Expand Down Expand Up @@ -465,6 +475,9 @@ static void __poller_handle_read(struct __poller_node *node,

if (nleft < 0)
break;

if (node->removed)
return;
}

if (__poller_remove_node(node, poller))
Expand Down Expand Up @@ -614,6 +627,9 @@ static void __poller_handle_listen(struct __poller_node *node,
node->res = res;
if (!res)
break;

if (node->removed)
return;
}

if (__poller_remove_node(node, poller))
Expand Down Expand Up @@ -689,6 +705,9 @@ static void __poller_handle_recvfrom(struct __poller_node *node,
node->res = res;
if (!res)
break;

if (node->removed)
return;
}

if (__poller_remove_node(node, poller))
Expand Down Expand Up @@ -828,6 +847,9 @@ static void __poller_handle_event(struct __poller_node *node,
node->res = res;
if (!res)
break;

if (node->removed)
return;
}
}

Expand Down Expand Up @@ -869,6 +891,9 @@ static void __poller_handle_notify(struct __poller_node *node,
node->res = res;
if (!res)
break;

if (node->removed)
return;
}
else if (n < 0 && errno == EAGAIN)
return;
Expand Down Expand Up @@ -1161,7 +1186,7 @@ poller_t *__poller_create(void **nodes_buf, const struct poller_params *params)
__poller_close_timerfd(poller->timerfd);
}

close(poller->pfd);
__poller_close_pfd(poller->pfd);
}

free(poller);
Expand Down Expand Up @@ -1189,7 +1214,7 @@ void __poller_destroy(poller_t *poller)
{
pthread_mutex_destroy(&poller->mutex);
__poller_close_timerfd(poller->timerfd);
close(poller->pfd);
__poller_close_pfd(poller->pfd);
free(poller);
}

Expand Down
Loading