Skip to content

Commit b3e42fe

Browse files
glenn-andrewsaescolar
authored andcommitted
Documentation: Update Polling API
Changes: 1. the number of events being checked did not equal those defined in the `events` array. 2. Use `k_poll_signal_check()` instead of accessing fields directly. 3. Use `k_poll_signal_reset()` to reset the signal instead of accessing fields directly. I'm assuming the examples predate `k_poll_signal_check()` and `k_poll_signal_reset()` Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
1 parent 94cd46d commit b3e42fe

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

doc/kernel/services/polling.rst

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ In case of success, :c:func:`k_poll` returns 0. If it times out, it returns
156156
157157
void do_stuff(void)
158158
{
159-
rc = k_poll(events, 2, 1000);
159+
rc = k_poll(events, ARRAY_SIZE(events), K_MSEC(1000));
160160
if (rc == 0) {
161161
if (events[0].state == K_POLL_STATE_SEM_AVAILABLE) {
162162
k_sem_take(events[0].sem, 0);
@@ -183,7 +183,7 @@ to :c:macro:`K_POLL_STATE_NOT_READY` by the user.
183183
void do_stuff(void)
184184
{
185185
for(;;) {
186-
rc = k_poll(events, 2, K_FOREVER);
186+
rc = k_poll(events, ARRAY_SIZE(events), K_FOREVER);
187187
if (events[0].state == K_POLL_STATE_SEM_AVAILABLE) {
188188
k_sem_take(events[0].sem, 0);
189189
} else if (events[1].state == K_POLL_STATE_FIFO_DATA_AVAILABLE) {
@@ -243,7 +243,11 @@ pass extra information to the thread waiting on the event.
243243
244244
k_poll(events, 1, K_FOREVER);
245245
246-
if (events.signal->result == 0x1337) {
246+
int signaled, result;
247+
248+
k_poll_signal_check(&signal, &signaled, &result);
249+
250+
if (signaled && (result == 0x1337)) {
247251
// A-OK!
248252
} else {
249253
// weird error
@@ -256,8 +260,10 @@ pass extra information to the thread waiting on the event.
256260
k_poll_signal_raise(&signal, 0x1337);
257261
}
258262
259-
If the signal is to be polled in a loop, *both* its event state and its
260-
**signaled** field *must* be reset on each iteration if it has been signaled.
263+
If the signal is to be polled in a loop, *both* its event state must be
264+
reset to :c:macro:`K_POLL_STATE_NOT_READY` *and* its ``result`` must be
265+
reset using :c:func:`k_poll_signal_reset()` on each iteration if it has
266+
been signaled.
261267

262268
.. code-block:: c
263269
@@ -275,13 +281,17 @@ If the signal is to be polled in a loop, *both* its event state and its
275281
for (;;) {
276282
k_poll(events, 1, K_FOREVER);
277283
278-
if (events[0].signal->result == 0x1337) {
284+
int signaled, result;
285+
286+
k_poll_signal_check(&signal, &signaled, &result);
287+
288+
if (signaled && (result == 0x1337)) {
279289
// A-OK!
280290
} else {
281291
// weird error
282292
}
283293
284-
events[0].signal->signaled = 0;
294+
k_poll_signal_reset(signal);
285295
events[0].state = K_POLL_STATE_NOT_READY;
286296
}
287297
}

0 commit comments

Comments
 (0)