Skip to content

Commit 80b40f3

Browse files
committed
Remove remaining pthread function from WASM_WORKERS build. NFC
This includes `pthread_self`, which is not valid to call in Wasm Workers.
1 parent 3d72f68 commit 80b40f3

File tree

7 files changed

+66
-67
lines changed

7 files changed

+66
-67
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ See docs/process.md for more on how version tagging works.
2323
- The deprecated `EMSCRIPTEN` macro is now defined in `emscripten.h` rather than
2424
on the command line (`__EMSCRIPTEN__`, which is built into LLVM, should be
2525
used instead). (#26417)
26+
- All pthread functions are now undefined when building with `-sWASM_WORKERS`.
27+
This is an extension of #26336 which removed many of them. (#26487)
2628

2729
5.0.3 - 03/14/26
2830
----------------

system/lib/pthread/emscripten_thread_state.S

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
.section .globals,"",@
88

9+
#ifndef __EMSCRIPTEN_WASM_WORKERS__
910
.globaltype thread_ptr, PTR
1011
thread_ptr:
12+
#endif
1113

1214
.globaltype is_main_thread, i32
1315
is_main_thread:
@@ -28,8 +30,10 @@ done_init:
2830
.globl __set_thread_state
2931
__set_thread_state:
3032
.functype __set_thread_state (PTR, i32, i32, i32) -> ()
33+
#ifndef __EMSCRIPTEN_WASM_WORKERS__
3134
local.get 0
3235
global.set thread_ptr
36+
#endif
3337
local.get 1
3438
global.set is_main_thread
3539
local.get 2
@@ -56,14 +60,13 @@ lazy_init_thread_state:
5660
end_function
5761
#endif
5862

63+
#ifndef __EMSCRIPTEN_WASM_WORKERS__
5964
.globl __get_tp
6065
__get_tp:
6166
.functype __get_tp () -> (PTR)
62-
#if __EMSCRIPTEN_WASM_WORKERS__
63-
call lazy_init_thread_state
64-
#endif
6567
global.get thread_ptr
6668
end_function
69+
#endif
6770

6871
# Semantically the same as testing "!ENVIRONMENT_IS_PTHREAD" in JS
6972
.globl emscripten_is_main_runtime_thread

system/lib/pthread/threading_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void _emscripten_thread_exit_joinable(pthread_t thread);
6969
void _emscripten_thread_exit(void* result);
7070
void _emscripten_process_dlopen_queue(void);
7171

72-
#ifdef NDEBUG
72+
#if defined(NDEBUG) || !defined(__EMSCRIPTEN_PTHREADS__)
7373
#define emscripten_set_current_thread_status(newStatus)
7474
#define emscripten_conditional_set_current_thread_status(expectedStatus, newStatus)
7575
#else

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"a.out.js": 244367,
3-
"a.out.nodebug.wasm": 577743,
4-
"total": 822110,
3+
"a.out.nodebug.wasm": 577708,
4+
"total": 822075,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",
@@ -2243,7 +2243,6 @@
22432243
"emscripten_proxy_sync",
22442244
"emscripten_proxy_sync_with_ctx",
22452245
"emscripten_scan_stack",
2246-
"emscripten_set_thread_name",
22472246
"emscripten_stack_get_base",
22482247
"emscripten_stack_get_current",
22492248
"emscripten_stack_get_end",
@@ -4100,7 +4099,6 @@
41004099
"$emscripten_proxy_async",
41014100
"$emscripten_proxy_execute_queue",
41024101
"$emscripten_scan_stack",
4103-
"$emscripten_set_thread_name",
41044102
"$emscripten_stack_get_base",
41054103
"$emscripten_stack_get_current",
41064104
"$emscripten_stack_get_end",

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": 7884,
33
"a.out.js.gz": 3855,
4-
"a.out.nodebug.wasm": 19707,
5-
"a.out.nodebug.wasm.gz": 9122,
6-
"total": 27591,
7-
"total_gz": 12977,
4+
"a.out.nodebug.wasm": 19775,
5+
"a.out.nodebug.wasm.gz": 9202,
6+
"total": 27659,
7+
"total_gz": 13057,
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": 8306,
33
"a.out.js.gz": 4060,
4-
"a.out.nodebug.wasm": 19708,
5-
"a.out.nodebug.wasm.gz": 9123,
6-
"total": 28014,
7-
"total_gz": 13183,
4+
"a.out.nodebug.wasm": 19776,
5+
"a.out.nodebug.wasm.gz": 9203,
6+
"total": 28082,
7+
"total_gz": 13263,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

tools/system_libs.py

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,56 +1211,10 @@ def get_files(self):
12111211
'pthread_kill.c',
12121212
'emscripten_thread_init.c',
12131213
'emscripten_yield.c',
1214+
'thread_profiler.c',
12141215
])
12151216
else:
12161217
ignore += ['thread']
1217-
libc_files += files_in_path(
1218-
path='system/lib/libc/musl/src/thread',
1219-
filenames=[
1220-
'pthread_self.c',
1221-
'pthread_cleanup_push.c',
1222-
'pthread_attr_init.c',
1223-
'pthread_attr_destroy.c',
1224-
'pthread_attr_get.c',
1225-
'pthread_attr_setdetachstate.c',
1226-
'pthread_attr_setguardsize.c',
1227-
'pthread_attr_setinheritsched.c',
1228-
'pthread_attr_setschedparam.c',
1229-
'pthread_attr_setschedpolicy.c',
1230-
'pthread_attr_setscope.c',
1231-
'pthread_attr_setstack.c',
1232-
'pthread_attr_setstacksize.c',
1233-
'pthread_getattr_np.c',
1234-
'pthread_getconcurrency.c',
1235-
'pthread_getcpuclockid.c',
1236-
'pthread_getschedparam.c',
1237-
'pthread_setschedprio.c',
1238-
'pthread_setconcurrency.c',
1239-
'default_attr.c',
1240-
# C11 thread library functions
1241-
'call_once.c',
1242-
'tss_create.c',
1243-
'tss_delete.c',
1244-
'tss_set.c',
1245-
'cnd_broadcast.c',
1246-
'cnd_destroy.c',
1247-
'cnd_init.c',
1248-
'cnd_signal.c',
1249-
'cnd_timedwait.c',
1250-
'cnd_wait.c',
1251-
'mtx_destroy.c',
1252-
'mtx_init.c',
1253-
'mtx_lock.c',
1254-
'mtx_timedlock.c',
1255-
'mtx_trylock.c',
1256-
'mtx_unlock.c',
1257-
'thrd_create.c',
1258-
'thrd_exit.c',
1259-
'thrd_join.c',
1260-
'thrd_sleep.c',
1261-
'thrd_yield.c',
1262-
])
1263-
12641218
libc_files += files_in_path(
12651219
path='system/lib/libc',
12661220
filenames=['emscripten_yield_stub.c'])
@@ -1285,6 +1239,52 @@ def get_files(self):
12851239
'pthread_self_stub.c',
12861240
'proxying_stub.c',
12871241
])
1242+
libc_files += files_in_path(
1243+
path='system/lib/libc/musl/src/thread',
1244+
filenames=[
1245+
'pthread_self.c',
1246+
'pthread_cleanup_push.c',
1247+
'pthread_attr_init.c',
1248+
'pthread_attr_destroy.c',
1249+
'pthread_attr_get.c',
1250+
'pthread_attr_setdetachstate.c',
1251+
'pthread_attr_setguardsize.c',
1252+
'pthread_attr_setinheritsched.c',
1253+
'pthread_attr_setschedparam.c',
1254+
'pthread_attr_setschedpolicy.c',
1255+
'pthread_attr_setscope.c',
1256+
'pthread_attr_setstack.c',
1257+
'pthread_attr_setstacksize.c',
1258+
'pthread_getattr_np.c',
1259+
'pthread_getconcurrency.c',
1260+
'pthread_getcpuclockid.c',
1261+
'pthread_getschedparam.c',
1262+
'pthread_setschedprio.c',
1263+
'pthread_setconcurrency.c',
1264+
'default_attr.c',
1265+
# C11 thread library functions
1266+
'call_once.c',
1267+
'tss_create.c',
1268+
'tss_delete.c',
1269+
'tss_set.c',
1270+
'cnd_broadcast.c',
1271+
'cnd_destroy.c',
1272+
'cnd_init.c',
1273+
'cnd_signal.c',
1274+
'cnd_timedwait.c',
1275+
'cnd_wait.c',
1276+
'mtx_destroy.c',
1277+
'mtx_init.c',
1278+
'mtx_lock.c',
1279+
'mtx_timedlock.c',
1280+
'mtx_trylock.c',
1281+
'mtx_unlock.c',
1282+
'thrd_create.c',
1283+
'thrd_exit.c',
1284+
'thrd_join.c',
1285+
'thrd_sleep.c',
1286+
'thrd_yield.c',
1287+
])
12881288

12891289
if self.is_mt or self.is_ww:
12901290
# Low level thread primitives available in both pthreads and wasm workers builds.
@@ -1412,10 +1412,6 @@ def get_files(self):
14121412
if settings.MAIN_MODULE:
14131413
libc_files += files_in_path(path='system/lib/libc', filenames=['dynlink.c'])
14141414

1415-
libc_files += files_in_path(
1416-
path='system/lib/pthread',
1417-
filenames=['thread_profiler.c'])
1418-
14191415
libc_files += glob_in_path('system/lib/libc/compat', '*.c')
14201416

14211417
# Check for missing file in non_lto_files list. Do this here

0 commit comments

Comments
 (0)