summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/modselect.c
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2023-11-30 14:32:41 +1100
committerDamien George <damien@micropython.org>2023-12-08 12:48:50 +1100
commitdf3948d3c23e3572c49d18ede03bf3ac97ee601c (patch)
tree7435061520a222a0ef859535a6c814d9eaffb486 /extmod/modselect.c
parentf5be0128e4da1417136495c20888f8291cd22386 (diff)
downloadmicropython-df3948d3c23e3572c49d18ede03bf3ac97ee601c.tar.gz
micropython-df3948d3c23e3572c49d18ede03bf3ac97ee601c.zip
extmod: Switch to use new event functions.
See previous commit for details of these functions. As of this commit, these still call the old hook macros on all ports. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'extmod/modselect.c')
-rw-r--r--extmod/modselect.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/extmod/modselect.c b/extmod/modselect.c
index d665a10827..07ef3d79c8 100644
--- a/extmod/modselect.c
+++ b/extmod/modselect.c
@@ -306,6 +306,7 @@ STATIC mp_uint_t poll_set_poll_once(poll_set_t *poll_set, size_t *rwx_num) {
STATIC mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size_t *rwx_num, mp_uint_t timeout) {
mp_uint_t start_ticks = mp_hal_ticks_ms();
+ bool has_timeout = timeout != (mp_uint_t)-1;
#if MICROPY_PY_SELECT_POSIX_OPTIMISATIONS
@@ -350,12 +351,12 @@ STATIC mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size
}
// Return if an object is ready, or if the timeout expired.
- if (n_ready > 0 || (timeout != (mp_uint_t)-1 && mp_hal_ticks_ms() - start_ticks >= timeout)) {
+ if (n_ready > 0 || (has_timeout && mp_hal_ticks_ms() - start_ticks >= timeout)) {
return n_ready;
}
- // This would be MICROPY_EVENT_POLL_HOOK but the call to poll() above already includes a delay.
- mp_handle_pending(true);
+ // This would be mp_event_wait_ms() but the call to poll() above already includes a delay.
+ mp_event_handle_nowait();
}
#else
@@ -363,10 +364,15 @@ STATIC mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size
for (;;) {
// poll the objects
mp_uint_t n_ready = poll_set_poll_once(poll_set, rwx_num);
- if (n_ready > 0 || (timeout != (mp_uint_t)-1 && mp_hal_ticks_ms() - start_ticks >= timeout)) {
+ uint32_t elapsed = mp_hal_ticks_ms() - start_ticks;
+ if (n_ready > 0 || (has_timeout && elapsed >= timeout)) {
return n_ready;
}
- MICROPY_EVENT_POLL_HOOK
+ if (has_timeout) {
+ mp_event_wait_ms(timeout - elapsed);
+ } else {
+ mp_event_wait_indefinite();
+ }
}
#endif