doc: kernel: fix k_poll example

Fix `k_poll()` loop example by using separate `if` blocks instead of
`if`-`else`-chain to ensure all events are handled, even if multiple are
active at the same time.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
This commit is contained in:
Cla Mattia Galliard 2024-08-09 09:08:11 +02:00 committed by Anas Nashif
commit 3552609a08

View file

@ -187,13 +187,16 @@ to :c:macro:`K_POLL_STATE_NOT_READY` by the user.
rc = k_poll(events, ARRAY_SIZE(events), K_FOREVER);
if (events[0].state == K_POLL_STATE_SEM_AVAILABLE) {
k_sem_take(events[0].sem, 0);
} else if (events[1].state == K_POLL_STATE_FIFO_DATA_AVAILABLE) {
}
if (events[1].state == K_POLL_STATE_FIFO_DATA_AVAILABLE) {
data = k_fifo_get(events[1].fifo, 0);
// handle data
} else if (events[2].state == K_POLL_STATE_MSGQ_DATA_AVAILABLE) {
}
if (events[2].state == K_POLL_STATE_MSGQ_DATA_AVAILABLE) {
ret = k_msgq_get(events[2].msgq, buf, K_NO_WAIT);
// handle data
} else if (events[3].state == K_POLL_STATE_PIPE_DATA_AVAILABLE) {
}
if (events[3].state == K_POLL_STATE_PIPE_DATA_AVAILABLE) {
ret = k_pipe_get(events[3].pipe, buf, bytes_to_read, &bytes_read, min_xfer, K_NO_WAIT);
// handle data
}