You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Minor refactoring of library_wasm_worker.js/wasm_worker.h. NFC (#20109)
- Format comment blocks to 80 chars
- Use {{{ cDefs }} rather than hardcoded numbers and comments
- Rename atomicLiveWaitAsyncs and liveAtomicWaitCounter for clarity.
Split out from #20099.
// _emscripten_wasm_worker_initialize() initializes the stack for this Worker,
63
-
// but it cannot call to extern __set_stack_limits() function, or Binaryen breaks
64
-
// with "Fatal: Module::addFunction: __set_stack_limits already exists".
65
-
// So for now, invoke this function from JS side. TODO: remove this in the future.
66
-
// Note that this call is not exactly correct, since this limit will include
67
-
// the TLS slot, that will be part of the region between m['sb'] and m['sz'],
68
-
// so we need to fix up the call below.
65
+
// _emscripten_wasm_worker_initialize() initializes the stack for this
66
+
// Worker, but it cannot call to extern __set_stack_limits() function, or
67
+
// Binaryen breaks with "Fatal: Module::addFunction: __set_stack_limits
68
+
// already exists". So for now, invoke this function from JS side. TODO:
69
+
// remove this in the future. Note that this call is not exactly correct,
70
+
// since this limit will include the TLS slot, that will be part of the
71
+
// region between m['sb'] and m['sz'], so we need to fix up the call below.
69
72
___set_stack_limits(m['sb']+m['sz'],m['sb']);
70
73
#endif
71
74
// Run the C side Worker initialization for stack and TLS.
@@ -100,33 +103,47 @@ addToLibrary({
100
103
},
101
104
102
105
#if WASM_WORKERS==2
103
-
// In WASM_WORKERS == 2 build mode, we create the Wasm Worker global scope script from a string bundled in the main application JS file. This simplifies the number of deployed JS files with the app,
104
-
// but has a downside that the generated build output will no longer be csp-eval compliant. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_eval_expressions
106
+
// In WASM_WORKERS == 2 build mode, we create the Wasm Worker global scope
107
+
// script from a string bundled in the main application JS file. This
108
+
// simplifies the number of deployed JS files with the app, but has a downside
109
+
// that the generated build output will no longer be csp-eval compliant.
#if WASM_WORKERS==2// WASM_WORKERS=2 mode embeds .ww.js file contents into the main .js file as a Blob URL. (convenient, but not CSP security safe, since this is eval-like)
128
+
#if WASM_WORKERS==2
129
+
// WASM_WORKERS=2 mode embeds .ww.js file contents into the main .js file
130
+
// as a Blob URL. (convenient, but not CSP security safe, since this is
131
+
// eval-like)
120
132
_wasmWorkerBlobUrl
121
-
#elif MINIMAL_RUNTIME// MINIMAL_RUNTIME has a structure where the .ww.js file is loaded from the main HTML file in parallel to all other files for best performance
133
+
#elif MINIMAL_RUNTIME
134
+
// MINIMAL_RUNTIME has a structure where the .ww.js file is loaded from
135
+
// the main HTML file in parallel to all other files for best performance
122
136
Module['$wb']// $wb="Wasm worker Blob", abbreviated since not DCEable
123
-
#else // default runtime loads the .ww.js file on demand.
137
+
#else
138
+
// default runtime loads the .ww.js file on demand.
124
139
locateFile('{{{ WASM_WORKER_FILE }}}')
125
140
#endif
126
141
);
127
142
// Craft the Module object for the Wasm Worker scope:
128
143
worker.postMessage({
129
-
'$ww': _wasmWorkersID,// Signal with a non-zero value that this Worker will be a Wasm Worker, and not the main browser thread.
144
+
// Signal with a non-zero value that this Worker will be a Wasm Worker,
145
+
// and not the main browser thread.
146
+
'$ww': _wasmWorkersID,
130
147
#if MINIMAL_RUNTIME
131
148
'wasm': Module['wasm'],
132
149
'js': Module['js'],
@@ -221,10 +238,12 @@ addToLibrary({
221
238
// And at the time of writing, no other browser has it either.
// Increment waitAsync generation counter, account for wraparound in case application does huge amounts of waitAsyncs per second (not sure if possible?)
299
+
// Increment waitAsync generation counter, account for wraparound in case
300
+
// application does huge amounts of waitAsyncs per second (not sure if
if(waitToken==1/* ATOMICS_WAIT_NOT_EQUAL */)warnOnce('Attempted to call emscripten_atomic_cancel_wait_async() with a value ATOMICS_WAIT_NOT_EQUAL (1) that is not a valid wait token! Check success in return value from call to emscripten_atomic_wait_async()');
297
-
elseif(waitToken==2/* ATOMICS_WAIT_TIMED_OUT */)warnOnce('Attempted to call emscripten_atomic_cancel_wait_async() with a value ATOMICS_WAIT_TIMED_OUT (2) that is not a valid wait token! Check success in return value from call to emscripten_atomic_wait_async()');
298
-
elseif(waitToken>0)warnOnce('Attempted to call emscripten_atomic_cancel_wait_async() with an invalid wait token value '+waitToken);
warnOnce('Attempted to call emscripten_atomic_cancel_wait_async() with a value ATOMICS_WAIT_NOT_EQUAL (1) that is not a valid wait token! Check success in return value from call to emscripten_atomic_wait_async()');
warnOnce('Attempted to call emscripten_atomic_cancel_wait_async() with a value ATOMICS_WAIT_TIMED_OUT (2) that is not a valid wait token! Check success in return value from call to emscripten_atomic_wait_async()');
322
+
}elseif(waitToken>0){
323
+
warnOnce(`Attempted to call emscripten_atomic_cancel_wait_async() with an invalid wait token value ${waitToken}`);
324
+
}
299
325
#endif
300
-
if(atomicLiveWaitAsyncs[waitToken]){
301
-
// Notify the waitAsync waiters on the memory location, so that JavaScript garbage collection can occur
326
+
if(liveAtomicWaitAsyncs[waitToken]){
327
+
// Notify the waitAsync waiters on the memory location, so that JavaScript
328
+
// garbage collection can occur.
302
329
// See https://github.com/WebAssembly/threads/issues/176
303
-
// This has the unfortunate effect of causing spurious wakeup of all other waiters at the address (which
0 commit comments