Skip to content

Commit 40064d6

Browse files
committed
Resolve test failures
By always calling `emscripten_main_thread_process_queued_calls()` before `emscripten_futex_wait()`.
1 parent c8d47d0 commit 40064d6

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ int __timedwait_cp(volatile int *addr, int val,
7878
// cancel execution.
7979
return ECANCELED;
8080
}
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);
8581
// Assist other threads by executing proxied operations that are effectively singlethreaded.
8682
if (is_runtime_thread) emscripten_main_thread_process_queued_calls();
8783

8884
msecsToSleep = sleepUntilTime - emscripten_get_now();
89-
} while (r == ETIMEDOUT && msecsToSleep > 0);
85+
if (msecsToSleep <= 0) {
86+
r = ETIMEDOUT;
87+
break;
88+
}
89+
// Must wait in slices in case this thread is cancelled in between.
90+
r = -emscripten_futex_wait((void*)addr, val,
91+
msecsToSleep > max_ms_slice_to_sleep ? max_ms_slice_to_sleep : msecsToSleep);
92+
} while (r == ETIMEDOUT);
9093
} else {
9194
// Can wait in one go.
9295
r = -emscripten_futex_wait((void*)addr, val, msecsToSleep);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ void __wait(volatile int *addr, volatile int *waiters, int val, int priv)
2828
if (waiters) a_dec(waiters);
2929
return;
3030
}
31-
// Must wait in slices in case this thread is cancelled in between.
32-
e = emscripten_futex_wait((void*)addr, val, max_ms_slice_to_sleep);
3331
// Assist other threads by executing proxied operations that are effectively singlethreaded.
3432
if (is_runtime_thread) emscripten_main_thread_process_queued_calls();
33+
// Must wait in slices in case this thread is cancelled in between.
34+
e = emscripten_futex_wait((void*)addr, val, max_ms_slice_to_sleep);
3535
} while (e == -ETIMEDOUT);
3636
} else {
3737
// Can wait in one go.

0 commit comments

Comments
 (0)