From 20028c7c807d91a1d8ce2195580005068112f9a5 Mon Sep 17 00:00:00 2001 From: stijn Date: Tue, 1 Mar 2022 11:44:15 +0100 Subject: [PATCH] windows: Avoid busy loop when using scheduler. --- ports/windows/mpconfigport.h | 18 ++++++++++-------- ports/windows/windows_mphal.c | 1 - 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index 4679d135655b..1d78f00320f6 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -228,22 +228,24 @@ extern const struct _mp_obj_module_t mp_module_time; #define MICROPY_MPHALPORT_H "windows_mphal.h" +// We need to provide a declaration/definition of alloca() +#include + +#include "realpath.h" +#include "init.h" +#include "sleep.h" + #if MICROPY_ENABLE_SCHEDULER +// Use 1mSec sleep to make sure there is effectively a wait period: +// something like usleep(500) truncates and ends up calling Sleep(0). #define MICROPY_EVENT_POLL_HOOK \ do { \ extern void mp_handle_pending(bool); \ mp_handle_pending(true); \ - mp_hal_delay_us(500); \ + msec_sleep(1.0); \ } while (0); #endif -// We need to provide a declaration/definition of alloca() -#include - -#include "realpath.h" -#include "init.h" -#include "sleep.h" - #ifdef __GNUC__ #define MP_NOINLINE __attribute__((noinline)) #endif diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index 7913435f75d4..17b20c30317c 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -280,7 +280,6 @@ void mp_hal_delay_ms(mp_uint_t ms) { #ifdef MICROPY_EVENT_POLL_HOOK mp_uint_t start = mp_hal_ticks_ms(); while (mp_hal_ticks_ms() - start < ms) { - // MICROPY_EVENT_POLL_HOOK does mp_hal_delay_us(500) (i.e. usleep(500)). MICROPY_EVENT_POLL_HOOK } #else