diff --git a/ChangeLog.md b/ChangeLog.md index 8499c9baad459..af574a3c18bc5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -23,6 +23,10 @@ See docs/process.md for more on how version tagging works. - The deprecated `EMSCRIPTEN` macro is now defined in `emscripten.h` rather than on the command line (`__EMSCRIPTEN__`, which is built into LLVM, should be used instead). (#26417) +- All pthread functions are now undefined when building with `-sWASM_WORKERS`. + This is an extension of #26336 which removed many of them. These APIs were + not previously functional under Wasm Workers, but if there is strong use case + it may be possible to enable them in future. (#26487) 5.0.3 - 03/14/26 ---------------- diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index 1457314ca764f..3e8cedf4c4758 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -566,9 +566,11 @@ class EMBIND_VISIBILITY_DEFAULT val { private: // takes ownership, assumes handle already incref'd and lives on the same thread - explicit val(EM_VAL handle) - : handle(handle), thread(pthread_self()) - {} + explicit val(EM_VAL handle) : +#ifdef _REENTRANT + thread(pthread_self()), +#endif + handle(handle) {} // Whether this value is a uses incref/decref (true) or is a special reserved // value (false). diff --git a/system/lib/pthread/emscripten_thread_state.S b/system/lib/pthread/emscripten_thread_state.S index 2060fb977acd5..ed5504dab462d 100644 --- a/system/lib/pthread/emscripten_thread_state.S +++ b/system/lib/pthread/emscripten_thread_state.S @@ -6,8 +6,10 @@ .section .globals,"",@ +#ifndef __EMSCRIPTEN_WASM_WORKERS__ .globaltype thread_ptr, PTR thread_ptr: +#endif .globaltype is_main_thread, i32 is_main_thread: @@ -28,8 +30,10 @@ done_init: .globl __set_thread_state __set_thread_state: .functype __set_thread_state (PTR, i32, i32, i32) -> () +#ifndef __EMSCRIPTEN_WASM_WORKERS__ local.get 0 global.set thread_ptr +#endif local.get 1 global.set is_main_thread local.get 2 @@ -56,14 +60,13 @@ lazy_init_thread_state: end_function #endif +#ifndef __EMSCRIPTEN_WASM_WORKERS__ .globl __get_tp __get_tp: .functype __get_tp () -> (PTR) -#if __EMSCRIPTEN_WASM_WORKERS__ - call lazy_init_thread_state -#endif global.get thread_ptr end_function +#endif # Semantically the same as testing "!ENVIRONMENT_IS_PTHREAD" in JS .globl emscripten_is_main_runtime_thread diff --git a/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json b/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json index 8c5404974899b..1140b98f22baa 100644 --- a/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json +++ b/test/codesize/test_minimal_runtime_code_size_hello_embind_val.json @@ -3,8 +3,8 @@ "a.html.gz": 371, "a.js": 5353, "a.js.gz": 2524, - "a.wasm": 5798, - "a.wasm.gz": 2731, - "total": 11699, - "total_gz": 5626 + "a.wasm": 5741, + "a.wasm.gz": 2690, + "total": 11642, + "total_gz": 5585 } diff --git a/tools/system_libs.py b/tools/system_libs.py index b443f6dc86c9c..b41ae353d04f1 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -1217,53 +1217,6 @@ def get_files(self): ]) else: ignore += ['thread'] - libc_files += files_in_path( - path='system/lib/libc/musl/src/thread', - filenames=[ - 'pthread_self.c', - 'pthread_cleanup_push.c', - 'pthread_attr_init.c', - 'pthread_attr_destroy.c', - 'pthread_attr_get.c', - 'pthread_attr_setdetachstate.c', - 'pthread_attr_setguardsize.c', - 'pthread_attr_setinheritsched.c', - 'pthread_attr_setschedparam.c', - 'pthread_attr_setschedpolicy.c', - 'pthread_attr_setscope.c', - 'pthread_attr_setstack.c', - 'pthread_attr_setstacksize.c', - 'pthread_getattr_np.c', - 'pthread_getconcurrency.c', - 'pthread_getcpuclockid.c', - 'pthread_getschedparam.c', - 'pthread_setschedprio.c', - 'pthread_setconcurrency.c', - 'default_attr.c', - # C11 thread library functions - 'call_once.c', - 'tss_create.c', - 'tss_delete.c', - 'tss_set.c', - 'cnd_broadcast.c', - 'cnd_destroy.c', - 'cnd_init.c', - 'cnd_signal.c', - 'cnd_timedwait.c', - 'cnd_wait.c', - 'mtx_destroy.c', - 'mtx_init.c', - 'mtx_lock.c', - 'mtx_timedlock.c', - 'mtx_trylock.c', - 'mtx_unlock.c', - 'thrd_create.c', - 'thrd_exit.c', - 'thrd_join.c', - 'thrd_sleep.c', - 'thrd_yield.c', - ]) - libc_files += files_in_path( path='system/lib/libc', filenames=['emscripten_yield_stub.c']) @@ -1288,6 +1241,52 @@ def get_files(self): 'pthread_self_stub.c', 'proxying_stub.c', ]) + libc_files += files_in_path( + path='system/lib/libc/musl/src/thread', + filenames=[ + 'pthread_self.c', + 'pthread_cleanup_push.c', + 'pthread_attr_init.c', + 'pthread_attr_destroy.c', + 'pthread_attr_get.c', + 'pthread_attr_setdetachstate.c', + 'pthread_attr_setguardsize.c', + 'pthread_attr_setinheritsched.c', + 'pthread_attr_setschedparam.c', + 'pthread_attr_setschedpolicy.c', + 'pthread_attr_setscope.c', + 'pthread_attr_setstack.c', + 'pthread_attr_setstacksize.c', + 'pthread_getattr_np.c', + 'pthread_getconcurrency.c', + 'pthread_getcpuclockid.c', + 'pthread_getschedparam.c', + 'pthread_setschedprio.c', + 'pthread_setconcurrency.c', + 'default_attr.c', + # C11 thread library functions + 'call_once.c', + 'tss_create.c', + 'tss_delete.c', + 'tss_set.c', + 'cnd_broadcast.c', + 'cnd_destroy.c', + 'cnd_init.c', + 'cnd_signal.c', + 'cnd_timedwait.c', + 'cnd_wait.c', + 'mtx_destroy.c', + 'mtx_init.c', + 'mtx_lock.c', + 'mtx_timedlock.c', + 'mtx_trylock.c', + 'mtx_unlock.c', + 'thrd_create.c', + 'thrd_exit.c', + 'thrd_join.c', + 'thrd_sleep.c', + 'thrd_yield.c', + ]) if self.is_mt or self.is_ww: # Low level thread primitives available in both pthreads and wasm workers builds.