Skip to content

Commit 54f145c

Browse files
committed
Avoid call to emscripten_futex_wait when msecsToSleep <= 0
1 parent 5b77bd9 commit 54f145c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

system/lib/libc/musl/src/thread/__timedwait.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ int __timedwait_cp(volatile int *addr, int val,
7878
// cancel execution.
7979
return ECANCELED;
8080
}
81-
// Must wait in slices in case this thread is cancelled in between.
82-
r = -emscripten_futex_wait((void*)addr, val,
83-
msecsToSleep > max_ms_slice_to_sleep ? max_ms_slice_to_sleep : msecsToSleep);
81+
if (msecsToSleep <= 0)
82+
// Must wait in slices in case this thread is cancelled in between.
83+
r = -emscripten_futex_wait((void*)addr, val,
84+
msecsToSleep > max_ms_slice_to_sleep ? max_ms_slice_to_sleep : msecsToSleep);
8485
// Assist other threads by executing proxied operations that are effectively singlethreaded.
8586
if (is_runtime_thread) emscripten_main_thread_process_queued_calls();
8687

0 commit comments

Comments
 (0)