Skip to content

Commit 49b4c9f

Browse files
committed
unix: Update port to use the new event functions.
Necessary to pass coverage on the initial PR. 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 unix port.) This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent adf61cd commit 49b4c9f

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

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