From f087aa264e918125ccb7c7fcf4614aad1b863e34 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 17 Apr 2025 00:27:30 -0400 Subject: [PATCH] kernel/pipe: fix poll support Two issues: - is_condition_met() was missing proper code for The K_POLL_TYPE_PIPE_DATA_AVAILABLE case - z_handle_obj_poll_events() was misplaced in z_impl_k_pipe_write() Note: I added support for the deprecated pipe implementation to is_condition_met() but that is untested. Signed-off-by: Nicolas Pitre --- kernel/pipe.c | 9 +++++---- kernel/poll.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kernel/pipe.c b/kernel/pipe.c index 09582260ab5..c5157ea6921 100644 --- a/kernel/pipe.c +++ b/kernel/pipe.c @@ -186,12 +186,13 @@ int z_impl_k_pipe_write(struct k_pipe *pipe, const uint8_t *data, size_t len, k_ break; } } -#ifdef CONFIG_POLL - z_handle_obj_poll_events(&pipe->poll_events, - K_POLL_STATE_PIPE_DATA_AVAILABLE); -#endif /* CONFIG_POLL */ } +#ifdef CONFIG_POLL + need_resched |= z_handle_obj_poll_events(&pipe->poll_events, + K_POLL_STATE_PIPE_DATA_AVAILABLE); +#endif /* CONFIG_POLL */ + written += ring_buf_put(&pipe->buf, &data[written], len - written); if (likely(written == len)) { rc = written; diff --git a/kernel/poll.c b/kernel/poll.c index a1930a6292f..b6e20b24c3a 100644 --- a/kernel/poll.c +++ b/kernel/poll.c @@ -88,8 +88,15 @@ static inline bool is_condition_met(struct k_poll_event *event, uint32_t *state) } break; case K_POLL_TYPE_PIPE_DATA_AVAILABLE: - *state = K_POLL_STATE_PIPE_DATA_AVAILABLE; - return true; +#ifdef CONFIG_PIPES + if (event->pipe->bytes_used != 0) { +#else + if (!ring_buf_is_empty(&event->pipe->buf)) { +#endif + *state = K_POLL_STATE_PIPE_DATA_AVAILABLE; + return true; + } + break; case K_POLL_TYPE_IGNORE: break; default: