Skip to content

Add Atomics.pause #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -55047,6 +55047,32 @@ static js_mutex_t js_atomics_mutex;
static struct list_head js_atomics_waiter_list =
LIST_HEAD_INIT(js_atomics_waiter_list);

// no-op: Atomics.pause() is not allowed to block or yield to another
// thread, only to hint the CPU that it should back off for a bit;
// the amount of work we do here is a good enough substitute
static JSValue js_atomics_pause(JSContext *ctx, JSValue this_obj,
int argc, JSValue *argv)
{
double d;

if (argc > 0) {
switch (JS_VALUE_GET_TAG(argv[0])) {
case JS_TAG_FLOAT64: // accepted if and only if fraction == 0.0
d = JS_VALUE_GET_FLOAT64(argv[0]);
if (isfinite(d))
if (0 == modf(d, &d))
break;
// fallthru
default:
return JS_ThrowTypeError(ctx, "not an integral number");
case JS_TAG_UNDEFINED:
case JS_TAG_INT:
break;
}
}
return JS_UNDEFINED;
}

static JSValue js_atomics_wait(JSContext *ctx,
JSValue this_obj,
int argc, JSValue *argv)
Expand Down Expand Up @@ -55176,6 +55202,7 @@ static const JSCFunctionListEntry js_atomics_funcs[] = {
JS_CFUNC_MAGIC_DEF("load", 2, js_atomics_op, ATOMICS_OP_LOAD ),
JS_CFUNC_DEF("store", 3, js_atomics_store ),
JS_CFUNC_DEF("isLockFree", 1, js_atomics_isLockFree ),
JS_CFUNC_DEF("pause", 0, js_atomics_pause ),
JS_CFUNC_DEF("wait", 4, js_atomics_wait ),
JS_CFUNC_DEF("notify", 3, js_atomics_notify ),
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "Atomics", JS_PROP_CONFIGURABLE ),
Expand Down
2 changes: 1 addition & 1 deletion test262.conf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async-functions
async-iteration
# atomics are broken in recent versions of tcc
Atomics=!tcc
Atomics.pause=skip
Atomics.pause=!tcc
Atomics.waitAsync=skip
BigInt
caller
Expand Down
Loading