Skip to content

Commit 51ecf89

Browse files
committed
Remove some of the complexity from __timedwait.c. NFC
This should have been part of #26471. The breaking up of the wait time for 2 of the 3 cases that are handled here is now handled one layer own in emscripten_futex_wait: 1. Breaking up the wait because we are the main runtime thread. 2. Breaking up the wait because we are async cancelable. The third cases here (breaking up the wait because we are cancelable in the non-async sense) still needs to be handled here at the higher level.
1 parent fce11ef commit 51ecf89

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,12 @@ int __timedwait_cp(volatile int *addr, int val,
5959

6060
#ifdef __EMSCRIPTEN__
6161
double msecsToSleep = top ? (top->tv_sec * 1000 + top->tv_nsec / 1000000.0) : INFINITY;
62-
int is_runtime_thread = emscripten_is_main_runtime_thread();
63-
64-
// Main runtime thread may need to run proxied calls, so sleep in very small slices to be responsive.
65-
double max_ms_slice_to_sleep = is_runtime_thread ? 1 : 100;
6662

6763
// cp suffix in the function name means "cancellation point", so this wait can be cancelled
6864
// by the users unless current threads cancelability is set to PTHREAD_CANCEL_DISABLE
6965
// which may be either done by the user of __timedwait() function.
70-
if (is_runtime_thread ||
71-
pthread_self()->canceldisable != PTHREAD_CANCEL_DISABLE ||
72-
pthread_self()->cancelasync) {
66+
if (pthread_self()->canceldisable != PTHREAD_CANCEL_DISABLE) {
67+
double max_ms_slice_to_sleep = 100;
7368
double sleepUntilTime = emscripten_get_now() + msecsToSleep;
7469
do {
7570
if (pthread_self()->cancel) {

test/codesize/test_codesize_minimal_pthreads.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 7364,
33
"a.out.js.gz": 3607,
4-
"a.out.nodebug.wasm": 19265,
5-
"a.out.nodebug.wasm.gz": 8934,
6-
"total": 26629,
7-
"total_gz": 12541,
4+
"a.out.nodebug.wasm": 19233,
5+
"a.out.nodebug.wasm.gz": 8918,
6+
"total": 26597,
7+
"total_gz": 12525,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

test/codesize/test_codesize_minimal_pthreads_memgrowth.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 7766,
33
"a.out.js.gz": 3812,
4-
"a.out.nodebug.wasm": 19266,
5-
"a.out.nodebug.wasm.gz": 8935,
6-
"total": 27032,
7-
"total_gz": 12747,
4+
"a.out.nodebug.wasm": 19234,
5+
"a.out.nodebug.wasm.gz": 8919,
6+
"total": 27000,
7+
"total_gz": 12731,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

0 commit comments

Comments
 (0)