Skip to content

Commit

Permalink
windows: Avoid busy loop when using scheduler.
Browse files Browse the repository at this point in the history
  • Loading branch information
stinos authored and dpgeorge committed May 4, 2022
1 parent 8aa79c9 commit 20028c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 10 additions & 8 deletions ports/windows/mpconfigport.h
Expand Up @@ -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 <malloc.h>

#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 <malloc.h>

#include "realpath.h"
#include "init.h"
#include "sleep.h"

#ifdef __GNUC__
#define MP_NOINLINE __attribute__((noinline))
#endif
Expand Down
1 change: 0 additions & 1 deletion ports/windows/windows_mphal.c
Expand Up @@ -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
Expand Down

0 comments on commit 20028c7

Please sign in to comment.