From 4b0032e1b60ac191d23beb072ac7c5fdea31d826 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Fri, 22 Dec 2023 18:17:02 -0800 Subject: [PATCH] Piggyback on existing async timer emulation instruction countdown for periodic emscripten_sleep() call. There is no need for an additional Emscripten-specific counter to periodically call emscripten_sleep(). Make test for Emscripten environment check MAIKO_OS_EMSCRIPTEN rather than checking __EMSCRIPTEN__, which is localized in the maiko/platform.h include. --- src/xc.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/xc.c b/src/xc.c index 644e00d..907b16b 100644 --- a/src/xc.c +++ b/src/xc.c @@ -20,6 +20,9 @@ /* */ /************************************************************************/ +#ifdef MAIKO_OS_EMSCRIPTEN +#include +#endif #include #include #include @@ -33,10 +36,6 @@ #include #endif /* DOS */ -#ifdef __EMSCRIPTEN__ -#include /* Defines emscripten_sleep */ -#endif /* __EMSCRIPTEN__ */ - #include "lispemul.h" #include "emlglob.h" #include "address.h" @@ -187,9 +186,6 @@ static int pseudoTimerAsyncCountdown = MAIKO_TIMER_ASYNC_EMULATION_INSNS_COUNTDO void dispatch(void) { InstPtr pccache; -#ifdef __EMSCRIPTEN__ - int cycles = 0; -#endif #if defined(OPDISP) static const void* optable[256] = { @@ -268,9 +264,6 @@ op_ufn : { /* DISPATCH "LOOP" */ nextopcode: -#ifdef __EMSCRIPTEN__ - if (++cycles % 1000000 == 0) emscripten_sleep(1); -#endif #ifdef MYOPTRACE if ((struct fnhead *)NativeAligned4FromLAddr(0x2ed600) == FuncObj) { quick_stack_check(); @@ -296,6 +289,9 @@ nextopcode: Irq_Stk_End = 0; #if defined(MAIKO_EMULATE_ASYNC_INTERRUPTS) IO_Signalled = TRUE; +#endif +#ifdef MAIKO_OS_EMSCRIPTEN + emscripten_sleep(1); #endif pseudoTimerAsyncCountdown = insnsCountdownForTimerAsyncEmulation; }