Skip to content

Commit ae8d76b

Browse files
authored
Auto-generate sigs for src/library_wasm_worker.js (#19263)
1 parent cb54282 commit ae8d76b

File tree

11 files changed

+116
-91
lines changed

11 files changed

+116
-91
lines changed

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ def phase_linker_setup(options, state, newargs):
24262426
wasm_worker_imports = ['_emscripten_wasm_worker_initialize', '___set_thread_state']
24272427
settings.EXPORTED_FUNCTIONS += wasm_worker_imports
24282428
building.user_requested_exports.update(wasm_worker_imports)
2429-
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['_wasm_worker_initializeRuntime']
2429+
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$_wasmWorkerInitializeRuntime']
24302430
# set location of Wasm Worker bootstrap JS file
24312431
if settings.WASM_WORKERS == 1:
24322432
settings.WASM_WORKER_FILE = unsuffixed(os.path.basename(target)) + '.ww.js'

src/library_sigs.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ sigs = {
298298
_embind_register_value_object__sig: 'vpppppp',
299299
_embind_register_value_object_field__sig: 'vpppppppppp',
300300
_embind_register_void__sig: 'vpp',
301+
_emscripten_create_wasm_worker__sig: 'ipi',
301302
_emscripten_dbg__sig: 'vp',
302303
_emscripten_default_pthread_stack_size__sig: 'i',
303304
_emscripten_dlopen_js__sig: 'vpppp',
@@ -505,6 +506,11 @@ sigs = {
505506
emscripten_async_wget2_abort__sig: 'vi',
506507
emscripten_async_wget2_data__sig: 'ippppippp',
507508
emscripten_async_wget_data__sig: 'vpppp',
509+
emscripten_atomic_cancel_all_wait_asyncs__sig: 'i',
510+
emscripten_atomic_cancel_all_wait_asyncs_at_address__sig: 'ip',
511+
emscripten_atomic_cancel_wait_async__sig: 'ii',
512+
emscripten_atomic_wait_async__sig: 'ipippd',
513+
emscripten_atomics_is_lock_free__sig: 'ii',
508514
emscripten_audio_context_state__sig: 'ii',
509515
emscripten_audio_worklet_post_function_sig__sig: 'vippp',
510516
emscripten_audio_worklet_post_function_v__sig: 'vip',
@@ -529,6 +535,7 @@ sigs = {
529535
emscripten_create_wasm_audio_worklet_processor_async__sig: 'vippp',
530536
emscripten_create_worker__sig: 'ip',
531537
emscripten_current_thread_is_audio_worklet__sig: 'i',
538+
emscripten_current_thread_is_wasm_worker__sig: 'i',
532539
emscripten_date_now__sig: 'd',
533540
emscripten_debugger__sig: 'v',
534541
emscripten_destroy_audio_context__sig: 'vi',
@@ -583,6 +590,7 @@ sigs = {
583590
emscripten_idb_load__sig: 'vppppp',
584591
emscripten_idb_store__sig: 'vpppip',
585592
emscripten_is_webgl_context_lost__sig: 'ii',
593+
emscripten_lock_async_acquire__sig: 'vpppd',
586594
emscripten_lock_orientation__sig: 'ii',
587595
emscripten_log__sig: 'vipp',
588596
emscripten_math_acos__sig: 'dd',
@@ -613,6 +621,7 @@ sigs = {
613621
emscripten_math_tan__sig: 'dd',
614622
emscripten_math_tanh__sig: 'dd',
615623
emscripten_memcpy_big__sig: 'vppp',
624+
emscripten_navigator_hardware_concurrency__sig: 'i',
616625
emscripten_notify_memory_growth__sig: 'vp',
617626
emscripten_num_logical_cores__sig: 'i',
618627
emscripten_pause_main_loop__sig: 'v',
@@ -652,6 +661,7 @@ sigs = {
652661
emscripten_runtime_keepalive_push__sig: 'v',
653662
emscripten_sample_gamepad_data__sig: 'i',
654663
emscripten_scan_registers__sig: 'vp',
664+
emscripten_semaphore_async_acquire__sig: 'vpippd',
655665
emscripten_set_batterychargingchange_callback_on_thread__sig: 'ippp',
656666
emscripten_set_batterylevelchange_callback_on_thread__sig: 'ippp',
657667
emscripten_set_beforeunload_callback_on_thread__sig: 'ippp',
@@ -714,6 +724,8 @@ sigs = {
714724
emscripten_start_fetch__sig: 'vp',
715725
emscripten_start_wasm_audio_worklet_thread_async__sig: 'vipipp',
716726
emscripten_supports_offscreencanvas__sig: 'i',
727+
emscripten_terminate_all_wasm_workers__sig: 'v',
728+
emscripten_terminate_wasm_worker__sig: 'vi',
717729
emscripten_throw_number__sig: 'vd',
718730
emscripten_throw_string__sig: 'vp',
719731
emscripten_trace_annotate_address_type__sig: 'vpp',
@@ -745,6 +757,15 @@ sigs = {
745757
emscripten_unwind_to_js_event_loop__sig: 'v',
746758
emscripten_vibrate__sig: 'ii',
747759
emscripten_vibrate_pattern__sig: 'ipi',
760+
emscripten_wasm_worker_post_function_sig__sig: 'vippp',
761+
emscripten_wasm_worker_post_function_v__sig: 'vip',
762+
emscripten_wasm_worker_post_function_vd__sig: 'vipd',
763+
emscripten_wasm_worker_post_function_vdd__sig: 'vipdd',
764+
emscripten_wasm_worker_post_function_vddd__sig: 'vipddd',
765+
emscripten_wasm_worker_post_function_vi__sig: 'vipi',
766+
emscripten_wasm_worker_post_function_vii__sig: 'vipii',
767+
emscripten_wasm_worker_post_function_viii__sig: 'vipiii',
768+
emscripten_wasm_worker_self_id__sig: 'i',
748769
emscripten_webgl_commit_frame__sig: 'i',
749770
emscripten_webgl_create_context__sig: 'ipp',
750771
emscripten_webgl_destroy_context__sig: 'ii',

src/library_wasm_worker.js

Lines changed: 66 additions & 68 deletions
Large diffs are not rendered by default.

src/library_webaudio.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ let LibraryWebAudio = {
123123

124124
#if AUDIO_WORKLET
125125
emscripten_start_wasm_audio_worklet_thread_async__deps: [
126-
'wasm_workers_id',
126+
'$_wasmWorkersID',
127127
'$_EmAudioDispatchProcessorCallback'],
128128
emscripten_start_wasm_audio_worklet_thread_async: function(contextHandle, stackLowestAddress, stackSize, callback, userData) {
129129

@@ -175,7 +175,7 @@ let LibraryWebAudio = {
175175
#endif
176176
audioWorklet.bootstrapMessage = new AudioWorkletNode(audioContext, 'message', {
177177
processorOptions: {
178-
'$ww': _wasm_workers_id++, // Assign the loaded AudioWorkletGlobalScope a Wasm Worker ID so that it can utilized its own TLS slots, and it is recognized to not be the main browser thread.
178+
'$ww': _wasmWorkersID++, // Assign the loaded AudioWorkletGlobalScope a Wasm Worker ID so that it can utilized its own TLS slots, and it is recognized to not be the main browser thread.
179179
#if MINIMAL_RUNTIME
180180
'wasm': Module['wasm'],
181181
'mem': wasmMemory,

src/postamble_minimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function initRuntime(asm) {
6565
#endif
6666

6767
#if WASM_WORKERS
68-
if (ENVIRONMENT_IS_WASM_WORKER) return __wasm_worker_initializeRuntime();
68+
if (ENVIRONMENT_IS_WASM_WORKER) return _wasmWorkerInitializeRuntime();
6969
#endif
7070

7171
#if STACK_OVERFLOW_CHECK

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function initRuntime() {
221221
runtimeInitialized = true;
222222

223223
#if WASM_WORKERS
224-
if (ENVIRONMENT_IS_WASM_WORKER) return __wasm_worker_initializeRuntime();
224+
if (ENVIRONMENT_IS_WASM_WORKER) return _wasmWorkerInitializeRuntime();
225225
#endif
226226

227227
#if PTHREADS

system/lib/libc/emscripten_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <emscripten/em_macros.h>
1515
#include <emscripten/proxying.h>
1616
#include <emscripten/html5.h>
17+
#include <emscripten/wasm_worker.h>
1718

1819
#include <signal.h> // for `sighandler_t`
1920
#include <stdbool.h> // for `bool`
@@ -132,6 +133,10 @@ void _emscripten_fetch_free(unsigned int);
132133

133134
EMSCRIPTEN_RESULT _emscripten_set_offscreencanvas_size(const char *target, int width, int height);
134135

136+
// Internal implementation function in JavaScript side that emscripten_create_wasm_worker() calls to
137+
// to perform the wasm worker creation.
138+
emscripten_wasm_worker_t _emscripten_create_wasm_worker(void *stackLowestAddress, uint32_t stackSize);
139+
135140
#ifdef __cplusplus
136141
}
137142
#endif

system/lib/wasm_worker/library_wasm_worker.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
#include <emscripten/stack.h>
66
#include <malloc.h>
77

8+
#include "emscripten_internal.h"
9+
810
#ifndef __EMSCRIPTEN_WASM_WORKERS__
911
#error __EMSCRIPTEN_WASM_WORKERS__ should be defined when building this file!
1012
#endif
1113

1214
// Options:
1315
// #define STACK_OVERFLOW_CHECK 0/1/2 : set to the current stack overflow check mode
1416

15-
// Internal implementation function in JavaScript side that emscripten_create_wasm_worker() calls to
16-
// to perform the wasm worker creation.
17-
emscripten_wasm_worker_t _emscripten_create_wasm_worker(void *stackLowestAddress, uint32_t stackSize);
18-
1917
void __wasm_init_tls(void *memory);
2018

2119
__attribute__((constructor(48)))

test/code_size/hello_wasm_worker_wasm.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@ var b = Module, c = b.$ww, f, e = b.mem || new WebAssembly.Memory({
22
initial: 256,
33
maximum: 256,
44
shared: !0
5-
}), g = e.buffer, h = {}, k = 1, m = [], p, q;
5+
}), g = e.buffer, h = [], m = {}, n = 1, p, q;
66

7-
function l(a) {
8-
m.push(a);
9-
}
10-
11-
function n(a) {
7+
function k(a) {
128
a = a.data;
139
let d = a._wsc;
1410
d && f.get(d)(...a.x);
1511
}
1612

17-
c && (h[0] = this, addEventListener("message", l));
13+
function l(a) {
14+
h.push(a);
15+
}
16+
17+
c && (m[0] = this, addEventListener("message", l));
1818

1919
WebAssembly.instantiate(b.wasm, {
2020
a: {
2121
b: function(a, d) {
22-
let r = h[k] = new Worker(b.$wb);
22+
let r = m[n] = new Worker(b.$wb);
2323
r.postMessage({
24-
$ww: k,
24+
$ww: n,
2525
wasm: b.wasm,
2626
js: b.js,
2727
mem: e,
2828
sb: a,
2929
sz: d
3030
});
31-
r.onmessage = n;
32-
return k++;
31+
r.onmessage = k;
32+
return n++;
3333
},
3434
c: function() {
3535
return !1;
3636
},
3737
d: function(a, d) {
38-
h[a].postMessage({
38+
m[a].postMessage({
3939
_wsc: d,
4040
x: []
4141
});
@@ -50,7 +50,7 @@ WebAssembly.instantiate(b.wasm, {
5050
p = a.g;
5151
q = a.i;
5252
f = a.h;
53-
c ? (a = b, q(a.sb, a.sz), removeEventListener("message", l), m = m.forEach(n),
54-
addEventListener("message", n)) : a.f();
53+
c ? (a = b, q(a.sb, a.sz), removeEventListener("message", l), h = h.forEach(k),
54+
addEventListener("message", k)) : a.f();
5555
c || p();
5656
}));

tools/gen_sig_info.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <emscripten/html5.h>
3838
#include <emscripten/fiber.h>
3939
#include <emscripten/websocket.h>
40+
#include <emscripten/wasm_worker.h>
4041
#include <emscripten/fetch.h>
4142
#include <emscripten/webaudio.h>
4243
#include <emscripten/threading.h>
@@ -354,6 +355,7 @@ def main(args):
354355

355356
print('generating signatures ...')
356357
sig_info = {}
358+
extract_sig_info(sig_info, {'WASM_WORKERS': 1, 'JS_LIBRARIES': ['src/library_wasm_worker.js']})
357359
extract_sig_info(sig_info, {'USE_GLFW': 3}, ['-DGLFW3'])
358360
extract_sig_info(sig_info, {'JS_LIBRARIES': ['src/embind/embind.js', 'src/embind/emval.js'],
359361
'USE_SDL': 0,

tools/system_libs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,7 @@ def can_use(self):
13341334

13351335
class libwasm_workers(MTLibrary):
13361336
name = 'libwasm_workers'
1337+
includes = ['system/lib/libc']
13371338

13381339
def __init__(self, **kwargs):
13391340
self.debug = kwargs.pop('debug')

0 commit comments

Comments
 (0)