Skip to content

Commit 8d29027

Browse files
projectgusdpgeorge
authored andcommitted
unix: Update port to use the new event functions.
Necessary to get coverage of the py/event.h inline functions. Deletes the case that called usleep(delay) for mp_hal_delay_ms(), it seems like this wouldn't have ever happened anyhow (MICROPY_EVENT_POOL_HOOK is always defined for the unix port). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent a701647 commit 8d29027

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

ports/unix/coverage.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "py/obj.h"
66
#include "py/objfun.h"
77
#include "py/objstr.h"
8+
#include "py/event.h"
89
#include "py/runtime.h"
910
#include "py/gc.h"
1011
#include "py/repl.h"
@@ -578,10 +579,10 @@ STATIC mp_obj_t extra_coverage(void) {
578579
mp_sched_unlock();
579580
mp_printf(&mp_plat_print, "unlocked\n");
580581

581-
// drain pending callbacks
582-
while (mp_sched_num_pending()) {
583-
mp_handle_pending(true);
584-
}
582+
// drain pending callbacks (and test mp_event_wait_ms())
583+
do {
584+
mp_event_wait_ms(1);
585+
} while (mp_sched_num_pending());
585586

586587
// setting the keyboard interrupt and raising it during mp_handle_pending
587588
mp_sched_keyboard_interrupt();

ports/unix/mpconfigport.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,10 @@ static inline unsigned long mp_random_seed_init(void) {
222222
#endif
223223

224224
// In lieu of a WFI(), slow down polling from being a tight loop.
225-
#ifndef MICROPY_EVENT_POLL_HOOK
226-
#define MICROPY_EVENT_POLL_HOOK \
227-
do { \
228-
extern void mp_handle_pending(bool); \
229-
mp_handle_pending(true); \
230-
usleep(500); /* equivalent to mp_hal_delay_us(500) */ \
231-
} while (0);
232-
#endif
225+
//
226+
// Note that we don't delay for the full TIMEOUT_MS, as execution
227+
// can't be woken from the delay.
228+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500)
233229

234230
// Configure the implementation of machine.idle().
235231
#include <sched.h>

ports/unix/unix_mphal.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "py/mphal.h"
3535
#include "py/mpthread.h"
36+
#include "py/event.h"
3637
#include "py/runtime.h"
3738
#include "extmod/misc.h"
3839

@@ -237,17 +238,10 @@ uint64_t mp_hal_time_ns(void) {
237238

238239
#ifndef mp_hal_delay_ms
239240
void mp_hal_delay_ms(mp_uint_t ms) {
240-
#ifdef MICROPY_EVENT_POLL_HOOK
241241
mp_uint_t start = mp_hal_ticks_ms();
242242
while (mp_hal_ticks_ms() - start < ms) {
243-
// MICROPY_EVENT_POLL_HOOK does usleep(500).
244-
MICROPY_EVENT_POLL_HOOK
243+
mp_event_wait_ms(1);
245244
}
246-
#else
247-
// TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:
248-
// "The useconds argument shall be less than one million."
249-
usleep(ms * 1000);
250-
#endif
251245
}
252246
#endif
253247

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy