Skip to content

Commit 3552609

Browse files
Cla Mattia Galliardnashif
authored andcommitted
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 <[email protected]>
1 parent 33407bf commit 3552609

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

doc/kernel/services/polling.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,16 @@ to :c:macro:`K_POLL_STATE_NOT_READY` by the user.
187187
rc = k_poll(events, ARRAY_SIZE(events), K_FOREVER);
188188
if (events[0].state == K_POLL_STATE_SEM_AVAILABLE) {
189189
k_sem_take(events[0].sem, 0);
190-
} else if (events[1].state == K_POLL_STATE_FIFO_DATA_AVAILABLE) {
190+
}
191+
if (events[1].state == K_POLL_STATE_FIFO_DATA_AVAILABLE) {
191192
data = k_fifo_get(events[1].fifo, 0);
192193
// handle data
193-
} else if (events[2].state == K_POLL_STATE_MSGQ_DATA_AVAILABLE) {
194+
}
195+
if (events[2].state == K_POLL_STATE_MSGQ_DATA_AVAILABLE) {
194196
ret = k_msgq_get(events[2].msgq, buf, K_NO_WAIT);
195197
// handle data
196-
} else if (events[3].state == K_POLL_STATE_PIPE_DATA_AVAILABLE) {
198+
}
199+
if (events[3].state == K_POLL_STATE_PIPE_DATA_AVAILABLE) {
197200
ret = k_pipe_get(events[3].pipe, buf, bytes_to_read, &bytes_read, min_xfer, K_NO_WAIT);
198201
// handle data
199202
}

0 commit comments

Comments
 (0)