@@ -55047,6 +55047,32 @@ static js_mutex_t js_atomics_mutex;
55047
55047
static struct list_head js_atomics_waiter_list =
55048
55048
LIST_HEAD_INIT(js_atomics_waiter_list);
55049
55049
55050
+ // no-op: Atomics.pause() is not allowed to block or yield to another
55051
+ // thread, only to hint the CPU that it should back off for a bit;
55052
+ // the amount of work we do here is a good enough substitute
55053
+ static JSValue js_atomics_pause(JSContext *ctx, JSValue this_obj,
55054
+ int argc, JSValue *argv)
55055
+ {
55056
+ double d;
55057
+
55058
+ if (argc > 0) {
55059
+ switch (JS_VALUE_GET_TAG(argv[0])) {
55060
+ case JS_TAG_FLOAT64: // accepted if and only if fraction == 0.0
55061
+ d = JS_VALUE_GET_FLOAT64(argv[0]);
55062
+ if (isfinite(d))
55063
+ if (0 == modf(d, &d))
55064
+ break;
55065
+ // fallthru
55066
+ default:
55067
+ return JS_ThrowTypeError(ctx, "not an integral number");
55068
+ case JS_TAG_UNDEFINED:
55069
+ case JS_TAG_INT:
55070
+ break;
55071
+ }
55072
+ }
55073
+ return JS_UNDEFINED;
55074
+ }
55075
+
55050
55076
static JSValue js_atomics_wait(JSContext *ctx,
55051
55077
JSValue this_obj,
55052
55078
int argc, JSValue *argv)
@@ -55176,6 +55202,7 @@ static const JSCFunctionListEntry js_atomics_funcs[] = {
55176
55202
JS_CFUNC_MAGIC_DEF("load", 2, js_atomics_op, ATOMICS_OP_LOAD ),
55177
55203
JS_CFUNC_DEF("store", 3, js_atomics_store ),
55178
55204
JS_CFUNC_DEF("isLockFree", 1, js_atomics_isLockFree ),
55205
+ JS_CFUNC_DEF("pause", 0, js_atomics_pause ),
55179
55206
JS_CFUNC_DEF("wait", 4, js_atomics_wait ),
55180
55207
JS_CFUNC_DEF("notify", 3, js_atomics_notify ),
55181
55208
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "Atomics", JS_PROP_CONFIGURABLE ),
0 commit comments