summaryrefslogtreecommitdiff
path: root/src/wasm2js.h
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2021-12-11 08:26:28 -0800
committerGitHub <noreply@github.com>2021-12-11 08:26:28 -0800
commit3b371d7e0fd0c9f77365b62268c4addcd6cd43be (patch)
tree15d0878e855a1afab7b31af846335ce93209e08b /src/wasm2js.h
parente0d043eb8bc4d0d6a474a0f3a68ccb7517a63342 (diff)
downloadbinaryen-3b371d7e0fd0c9f77365b62268c4addcd6cd43be.tar.gz
binaryen-3b371d7e0fd0c9f77365b62268c4addcd6cd43be.tar.bz2
binaryen-3b371d7e0fd0c9f77365b62268c4addcd6cd43be.zip
Implement timeout argument in wasm2js_atomic_wait_i32 (#4385)
Also, fix bug where pointer was being used direcltly to index into Int32Array. I suppose this code had basically zero users until I tried to land this change in emscripten: https://github.com/emscripten-core/emscripten/pull/15742
Diffstat (limited to 'src/wasm2js.h')
-rw-r--r--src/wasm2js.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h
index 7c9bef0ba..615e47268 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -2856,9 +2856,14 @@ void Wasm2JSGlue::emitSpecialSupport() {
} else if (import->base == ABI::wasm2js::ATOMIC_WAIT_I32) {
out << R"(
function wasm2js_atomic_wait_i32(ptr, expected, timeoutLow, timeoutHigh) {
- if (timeoutLow != -1 || timeoutHigh != -1) throw 'unsupported timeout';
+ var timeout = Infinity;
+ if (timeoutHigh >= 0) {
+ // Convert from nanoseconds to milliseconds
+ // Taken from convertI32PairToI53 in emscripten's library_int53.js
+ timeout = ((timeoutLow / 1e6) >>> 0) + timeoutHigh * (4294967296 / 1e6);
+ }
var view = new Int32Array(bufferView.buffer); // TODO cache
- var result = Atomics.wait(view, ptr, expected);
+ var result = Atomics.wait(view, ptr >> 2, expected, timeout);
if (result == 'ok') return 0;
if (result == 'not-equal') return 1;
if (result == 'timed-out') return 2;