diff --git a/system/lib/libc/musl/src/thread/__timedwait.c b/system/lib/libc/musl/src/thread/__timedwait.c index eb1e498b879ca..c90b94df73618 100644 --- a/system/lib/libc/musl/src/thread/__timedwait.c +++ b/system/lib/libc/musl/src/thread/__timedwait.c @@ -67,12 +67,13 @@ int __timedwait_cp(volatile int *addr, int val, // 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. + pthread_t self = pthread_self(); if (is_runtime_thread || - pthread_self()->canceldisable != PTHREAD_CANCEL_DISABLE || - pthread_self()->cancelasync) { + self->canceldisable != PTHREAD_CANCEL_DISABLE || + self->cancelasync) { double sleepUntilTime = emscripten_get_now() + msecsToSleep; do { - if (pthread_self()->cancel) { + if (self->cancel) { // The thread was canceled by pthread_cancel(). // In the case of cancelasync or PTHREAD_CANCEL_ENABLE we can just call // __pthread_testcancel(), which won't return at all. diff --git a/system/lib/pthread/emscripten_futex_wait.c b/system/lib/pthread/emscripten_futex_wait.c index c7265abe84c73..3f129f35ca2e2 100644 --- a/system/lib/pthread/emscripten_futex_wait.c +++ b/system/lib/pthread/emscripten_futex_wait.c @@ -130,7 +130,8 @@ int emscripten_futex_wait(volatile void *addr, uint32_t val, double max_wait_ms) emscripten_conditional_set_current_thread_status(EM_THREAD_STATUS_RUNNING, EM_THREAD_STATUS_WAITFUTEX); #ifdef __EMSCRIPTEN_PTHREADS__ - bool cancelable = pthread_self()->cancelasync == PTHREAD_CANCEL_ASYNCHRONOUS; + pthread_t self = pthread_self(); + bool cancelable = self->cancelasync == PTHREAD_CANCEL_ASYNCHRONOUS; #else bool cancelable = false; #endif @@ -199,19 +200,19 @@ int emscripten_futex_wait(volatile void *addr, uint32_t val, double max_wait_ms) // the queue, either from the call here directly after setting `sleeping` to // 1, or from another callsite (e.g. the one in `emscripten_yield`). if (!is_runtime_thread) { - __pthread_self()->sleeping = 1; + self->sleeping = 1; _emscripten_process_dlopen_queue(); } #endif ret = __builtin_wasm_memory_atomic_wait32((int*)addr, val, max_wait_ns); #ifdef EMSCRIPTEN_DYNAMIC_LINKING if (!is_runtime_thread) { - __pthread_self()->sleeping = 0; + self->sleeping = 0; _emscripten_process_dlopen_queue(); } #endif #ifdef __EMSCRIPTEN_PTHREADS__ - if (cancelable && ret == ATOMICS_WAIT_TIMED_OUT && pthread_self()->cancel) { + if (cancelable && ret == ATOMICS_WAIT_TIMED_OUT && self->cancel) { // Break out of the loop early if we were cancelled break; } diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index da85c8790e0ef..fdc8644fad454 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,9 +1,9 @@ { "a.out.js": 7364, "a.out.js.gz": 3607, - "a.out.nodebug.wasm": 19265, + "a.out.nodebug.wasm": 19263, "a.out.nodebug.wasm.gz": 8934, - "total": 26629, + "total": 26627, "total_gz": 12541, "sent": [ "a (memory)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index a96e1eea00ba9..3e8d423f00fa0 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,9 +1,9 @@ { "a.out.js": 7766, "a.out.js.gz": 3812, - "a.out.nodebug.wasm": 19266, + "a.out.nodebug.wasm": 19264, "a.out.nodebug.wasm.gz": 8935, - "total": 27032, + "total": 27030, "total_gz": 12747, "sent": [ "a (memory)",