Add emscripten_sleep() wrapper to libc-emcc (#3669)

This commit is contained in:
Benbuck Nason
2024-07-29 19:52:44 -07:00
committed by GitHub
parent a9cd8ba87a
commit 6be4b53bdf

View File

@ -495,6 +495,24 @@ emscripten_notify_memory_growth_wrapper(wasm_exec_env_t exec_env, int i)
(void)i;
}
static void
emscripten_sleep_wrapper(wasm_exec_env_t exec_env, int timeout_ms)
{
unsigned int sec;
useconds_t us;
if (timeout_ms <= 0)
return;
sec = timeout_ms / 1000;
us = (timeout_ms % 1000) * 1000;
if (sec > 0)
sleep(sec);
if (us > 0)
usleep(us);
}
static void
emscripten_thread_sleep_wrapper(wasm_exec_env_t exec_env, double timeout_ms)
{
@ -544,6 +562,7 @@ static NativeSymbol native_symbols_libc_emcc[] = {
REG_NATIVE_FUNC(__sys_getcwd, "(*~)i"),
REG_NATIVE_FUNC(__sys_uname, "(*)i"),
REG_NATIVE_FUNC(emscripten_notify_memory_growth, "(i)"),
REG_NATIVE_FUNC(emscripten_sleep, "(i)"),
REG_NATIVE_FUNC(emscripten_thread_sleep, "(F)"),
#endif /* end of BH_PLATFORM_LINUX_SGX */
};