diff --git a/system/lib/libc/musl/src/thread/__timedwait.c b/system/lib/libc/musl/src/thread/__timedwait.c index c90b94df73618..5d37774c8555a 100644 --- a/system/lib/libc/musl/src/thread/__timedwait.c +++ b/system/lib/libc/musl/src/thread/__timedwait.c @@ -61,9 +61,6 @@ int __timedwait_cp(volatile int *addr, int val, double msecsToSleep = top ? (top->tv_sec * 1000 + top->tv_nsec / 1000000.0) : INFINITY; int is_runtime_thread = emscripten_is_main_runtime_thread(); - // Main runtime thread may need to run proxied calls, so sleep in very small slices to be responsive. - double max_ms_slice_to_sleep = is_runtime_thread ? 1 : 100; - // cp suffix in the function name means "cancellation point", so this wait can be cancelled // by the users unless current threads cancelability is set to PTHREAD_CANCEL_DISABLE // which may be either done by the user of __timedwait() function. @@ -71,6 +68,9 @@ int __timedwait_cp(volatile int *addr, int val, if (is_runtime_thread || self->canceldisable != PTHREAD_CANCEL_DISABLE || self->cancelasync) { + // Main runtime thread may need to run proxied calls, so sleep in very small slices to be responsive. + double max_ms_slice_to_sleep = is_runtime_thread ? 1 : 100; + double sleepUntilTime = emscripten_get_now() + msecsToSleep; do { if (self->cancel) { diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index 46134024d4f69..ed8abbc889665 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { "a.out.js": 7363, "a.out.js.gz": 3604, - "a.out.nodebug.wasm": 19259, - "a.out.nodebug.wasm.gz": 8931, - "total": 26622, - "total_gz": 12535, + "a.out.nodebug.wasm": 19256, + "a.out.nodebug.wasm.gz": 8935, + "total": 26619, + "total_gz": 12539, "sent": [ "a (memory)", "b (emscripten_get_now)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index bd269f796de58..50a3f3afc8a34 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { "a.out.js": 7765, "a.out.js.gz": 3810, - "a.out.nodebug.wasm": 19260, - "a.out.nodebug.wasm.gz": 8933, - "total": 27025, - "total_gz": 12743, + "a.out.nodebug.wasm": 19257, + "a.out.nodebug.wasm.gz": 8936, + "total": 27022, + "total_gz": 12746, "sent": [ "a (memory)", "b (emscripten_get_now)",