Skip to content

Commit 3ca01ec

Browse files
danicamporadpgeorge
authored andcommitted
zephyr/mphalport: Make mp_hal_wait_sem() always call k_poll().
Also even in the case of a zero timeout given. Signed-off-by: danicampora <danicampora@gmail.com>
1 parent 1c0dc2a commit 3ca01ec

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ports/zephyr/mphalport.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,11 @@ void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms) {
5454
mp_handle_pending(true);
5555
MP_THREAD_GIL_EXIT();
5656
k_timeout_t wait;
57+
uint32_t dt = mp_hal_ticks_ms() - t0;
5758
if (timeout_ms == (uint32_t)-1) {
5859
wait = K_FOREVER;
5960
} else {
60-
uint32_t dt = mp_hal_ticks_ms() - t0;
61-
if (dt >= timeout_ms) {
62-
MP_THREAD_GIL_ENTER();
63-
return;
64-
}
65-
wait = K_MSEC(timeout_ms - dt);
61+
wait = K_MSEC((timeout_ms > dt) ? (timeout_ms - dt) : 0);
6662
}
6763
k_poll(wait_events, sem ? 2 : 1, wait);
6864
if (wait_events[0].state == K_POLL_STATE_SIGNALED) {
@@ -73,5 +69,9 @@ void mp_hal_wait_sem(struct k_sem *sem, uint32_t timeout_ms) {
7369
MP_THREAD_GIL_ENTER();
7470
return;
7571
}
72+
if (dt >= timeout_ms) {
73+
MP_THREAD_GIL_ENTER();
74+
return;
75+
}
7676
}
7777
}

0 commit comments

Comments
 (0)