summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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;