windows: Avoid busy loop when using scheduler.

This commit is contained in:
stijn 2022-03-01 11:44:15 +01:00 committed by Damien George
parent 8aa79c95bd
commit 20028c7c80
2 changed files with 11 additions and 10 deletions

View File

@ -228,15 +228,6 @@ extern const struct _mp_obj_module_t mp_module_time;
#define MICROPY_MPHALPORT_H "windows_mphal.h"
#if MICROPY_ENABLE_SCHEDULER
#define MICROPY_EVENT_POLL_HOOK \
do { \
extern void mp_handle_pending(bool); \
mp_handle_pending(true); \
mp_hal_delay_us(500); \
} while (0);
#endif
// We need to provide a declaration/definition of alloca()
#include <malloc.h>
@ -244,6 +235,17 @@ extern const struct _mp_obj_module_t mp_module_time;
#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); \
msec_sleep(1.0); \
} while (0);
#endif
#ifdef __GNUC__
#define MP_NOINLINE __attribute__((noinline))
#endif

View File

@ -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