Skip to content

Commit 6be4b53

Browse files
authored
Add emscripten_sleep() wrapper to libc-emcc (#3669)
1 parent a9cd8ba commit 6be4b53

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,24 @@ emscripten_notify_memory_growth_wrapper(wasm_exec_env_t exec_env, int i)
495495
(void)i;
496496
}
497497

498+
static void
499+
emscripten_sleep_wrapper(wasm_exec_env_t exec_env, int timeout_ms)
500+
{
501+
unsigned int sec;
502+
useconds_t us;
503+
504+
if (timeout_ms <= 0)
505+
return;
506+
507+
sec = timeout_ms / 1000;
508+
us = (timeout_ms % 1000) * 1000;
509+
510+
if (sec > 0)
511+
sleep(sec);
512+
if (us > 0)
513+
usleep(us);
514+
}
515+
498516
static void
499517
emscripten_thread_sleep_wrapper(wasm_exec_env_t exec_env, double timeout_ms)
500518
{
@@ -544,6 +562,7 @@ static NativeSymbol native_symbols_libc_emcc[] = {
544562
REG_NATIVE_FUNC(__sys_getcwd, "(*~)i"),
545563
REG_NATIVE_FUNC(__sys_uname, "(*)i"),
546564
REG_NATIVE_FUNC(emscripten_notify_memory_growth, "(i)"),
565+
REG_NATIVE_FUNC(emscripten_sleep, "(i)"),
547566
REG_NATIVE_FUNC(emscripten_thread_sleep, "(F)"),
548567
#endif /* end of BH_PLATFORM_LINUX_SGX */
549568
};

0 commit comments

Comments
 (0)