Skip to content

Commit a4e5704

Browse files
committed
Fix async futex wait in WASM worker dose not keep runtime alive
Fix asynchronous futex wait `emscripten_atomic_wait_async` in WASM worker dose not keep runtime alive.
1 parent 0c21eb9 commit a4e5704

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/library_wasm_worker.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,24 @@ Atomics.waitAsync = (i32a, index, value, maxWaitMilliseconds) => {
292292
$liveAtomicWaitAsyncs: '{}',
293293
$liveAtomicWaitAsyncCounter: '0',
294294

295-
emscripten_atomic_wait_async__deps: ['$atomicWaitStates', '$liveAtomicWaitAsyncs', '$liveAtomicWaitAsyncCounter', '$jstoi_q'],
295+
emscripten_atomic_wait_async__deps: ['$atomicWaitStates', '$liveAtomicWaitAsyncs', '$liveAtomicWaitAsyncCounter', '$jstoi_q',
296+
#if !MINIMAL_RUNTIME
297+
'$runtimeKeepalivePush', '$runtimeKeepalivePop',
298+
#endif
299+
],
296300
emscripten_atomic_wait_async: (addr, val, asyncWaitFinished, userData, maxWaitMilliseconds) => {
297301
let wait = Atomics.waitAsync(HEAP32, {{{ getHeapOffset('addr', 'i32') }}}, val, maxWaitMilliseconds);
298302
if (!wait.async) return atomicWaitStates.indexOf(wait.value);
299303
// Increment waitAsync generation counter, account for wraparound in case
300304
// application does huge amounts of waitAsyncs per second (not sure if
301305
// possible?)
302306
// Valid counterrange: 0...2^31-1
307+
{{{ runtimeKeepalivePush() }}}
303308
let counter = liveAtomicWaitAsyncCounter;
304309
liveAtomicWaitAsyncCounter = Math.max(0, (liveAtomicWaitAsyncCounter+1)|0);
305310
liveAtomicWaitAsyncs[counter] = addr;
306311
wait.value.then((value) => {
312+
{{{ runtimeKeepalivePop() }}}
307313
if (liveAtomicWaitAsyncs[counter]) {
308314
delete liveAtomicWaitAsyncs[counter];
309315
{{{ makeDynCall('vpiip', 'asyncWaitFinished') }}}(addr, val, atomicWaitStates.indexOf(value), userData);

0 commit comments

Comments
 (0)