From 45eda0010db1f5b4c152442a413ad135cf709703 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 20 Mar 2026 13:16:12 -0700 Subject: [PATCH] [embind] Only initialize pthread member in multi-threaded builds. NFC Split out from #26487 --- system/include/emscripten/val.h | 8 +++++--- .../test_minimal_runtime_code_size_hello_embind_val.json | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) 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/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 }