diff --git a/src/lib/libatomic.js b/src/lib/libatomic.js index bad0b05a7950e..f83f8c635c1ae 100644 --- a/src/lib/libatomic.js +++ b/src/lib/libatomic.js @@ -22,7 +22,9 @@ addToLibrary({ // https://github.com/tc39/proposal-atomics-wait-async/blob/master/PROPOSAL.md // This polyfill performs polling with setTimeout() to observe a change in the // target memory location. - $polyfillWaitAsync__postset: `if (!Atomics.waitAsync || (globalThis.navigator?.userAgent && Number((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91)) { + $waitAsyncPolyfilled: '=(!Atomics.waitAsync || (globalThis.navigator?.userAgent && Number((navigator.userAgent.match(/Chrom(e|ium)\\/([0-9]+)\\./)||[])[2]) < 91));', + $polyfillWaitAsync__deps: ['$waitAsyncPolyfilled'], + $polyfillWaitAsync__postset: `if (waitAsyncPolyfilled) { let __Atomics_waitAsyncAddresses = [/*[i32a, index, value, maxWaitMilliseconds, promiseResolve]*/]; function __Atomics_pollWaitAsyncAddresses() { let now = performance.now(); diff --git a/src/lib/libpthread.js b/src/lib/libpthread.js index 83f0501a52f46..29a30985b1354 100644 --- a/src/lib/libpthread.js +++ b/src/lib/libpthread.js @@ -1261,9 +1261,9 @@ var LibraryPThread = { } }), - _emscripten_thread_mailbox_await__deps: ['$checkMailbox'], + _emscripten_thread_mailbox_await__deps: ['$checkMailbox', '$waitAsyncPolyfilled'], _emscripten_thread_mailbox_await: (pthread_ptr) => { - if (Atomics.waitAsync) { + if (!waitAsyncPolyfilled) { // Wait on the pthread's initial self-pointer field because it is easy and // safe to access from sending threads that need to notify the waiting // thread.