Skip to content

Commit

Permalink
zephyr/mphalport: Make mp_hal_wait_sem() always call k_poll().
Browse files Browse the repository at this point in the history
Also even in the case of a zero timeout given.

Signed-off-by: danicampora <danicampora@gmail.com>
  • Loading branch information
danicampora authored and dpgeorge committed Sep 6, 2024
1 parent 1c0dc2a commit 3ca01ec
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ports/zephyr/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@ void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms) {
mp_handle_pending(true);
MP_THREAD_GIL_EXIT();
k_timeout_t wait;
uint32_t dt = mp_hal_ticks_ms() - t0;
if (timeout_ms == (uint32_t)-1) {
wait = K_FOREVER;
} else {
uint32_t dt = mp_hal_ticks_ms() - t0;
if (dt >= timeout_ms) {
MP_THREAD_GIL_ENTER();
return;
}
wait = K_MSEC(timeout_ms - dt);
wait = K_MSEC((timeout_ms > dt) ? (timeout_ms - dt) : 0);
}
k_poll(wait_events, sem ? 2 : 1, wait);
if (wait_events[0].state == K_POLL_STATE_SIGNALED) {
Expand All @@ -73,5 +69,9 @@ void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms) {
MP_THREAD_GIL_ENTER();
return;
}
if (dt >= timeout_ms) {
MP_THREAD_GIL_ENTER();
return;
}
}
}

0 comments on commit 3ca01ec

Please sign in to comment.