Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1481)

Unified Diff: src/harmony-atomics.js

Issue 1208933006: Atomics Futex API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: error message Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/harmony-atomics.js
diff --git a/src/harmony-atomics.js b/src/harmony-atomics.js
index aa81822d1e2f877f4de933f02d269b81775eea11..0eb496dae1d49fc0c1e4ebf110d49351983088d3 100644
--- a/src/harmony-atomics.js
+++ b/src/harmony-atomics.js
@@ -13,6 +13,12 @@
var GlobalObject = global.Object;
+var MathMax;
+
+utils.Import(function(from) {
+ MathMax = from.MathMax;
+});
+
// -------------------------------------------------------------------
@@ -28,6 +34,13 @@ function CheckSharedIntegerTypedArray(ia) {
}
}
+function CheckSharedInteger32TypedArray(ia) {
+ CheckSharedIntegerTypedArray(ia);
+ if (%_ClassOf(ia) !== 'Int32Array') {
+ throw MakeTypeError(kNotInt32SharedTypedArray, ia);
+ }
+}
+
//-------------------------------------------------------------------
function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) {
@@ -115,6 +128,49 @@ function AtomicsIsLockFreeJS(size) {
return %_AtomicsIsLockFree(size);
}
+// Futexes
+
+function AtomicsFutexWaitJS(ia, index, value, timeout) {
+ CheckSharedInteger32TypedArray(ia);
+ index = $toInteger(index);
+ if (index < 0 || index >= ia.length) {
+ return UNDEFINED;
+ }
+ if (IS_UNDEFINED(timeout)) {
+ timeout = INFINITY;
+ } else {
+ timeout = $toNumber(timeout);
+ if (NUMBER_IS_NAN(timeout)) {
+ timeout = INFINITY;
+ } else {
+ timeout = MathMax(0, timeout);
+ }
+ }
+ return %_AtomicsFutexWait(ia, index, value, timeout);
Michael Starzinger 2015/07/08 17:54:20 The %_FooBar syntax is used to indicate that at le
binji 2015/07/08 18:05:29 Done.
+}
+
+function AtomicsFutexWakeJS(ia, index, count) {
+ CheckSharedInteger32TypedArray(ia);
+ index = $toInteger(index);
+ if (index < 0 || index >= ia.length) {
+ return UNDEFINED;
+ }
+ count = MathMax(0, $toInteger(count));
+ return %_AtomicsFutexWake(ia, index, count);
+}
+
+function AtomicsFutexWakeOrRequeueJS(ia, index1, count, value, index2) {
+ CheckSharedInteger32TypedArray(ia);
+ index1 = $toInteger(index1);
+ count = MathMax(0, $toInteger(count));
+ value = $toInt32(value);
+ index2 = $toInteger(index2);
+ if (index1 < 0 || index1 >= ia.length || index2 < 0 || index2 >= ia.length) {
+ return UNDEFINED;
+ }
+ return %_AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2);
+}
+
// -------------------------------------------------------------------
function AtomicsConstructor() {}
@@ -127,6 +183,13 @@ var Atomics = new AtomicsConstructor();
%AddNamedProperty(Atomics, symbolToStringTag, "Atomics", READ_ONLY | DONT_ENUM);
+// These must match the values in src/futex-emulation.h
+utils.InstallConstants(Atomics, [
+ "OK", 0,
+ "NOTEQUAL", -1,
+ "TIMEDOUT", -2,
+]);
+
utils.InstallFunctions(Atomics, DONT_ENUM, [
"compareExchange", AtomicsCompareExchangeJS,
"load", AtomicsLoadJS,
@@ -138,6 +201,9 @@ utils.InstallFunctions(Atomics, DONT_ENUM, [
"xor", AtomicsXorJS,
"exchange", AtomicsExchangeJS,
"isLockFree", AtomicsIsLockFreeJS,
+ "futexWait", AtomicsFutexWaitJS,
+ "futexWake", AtomicsFutexWakeJS,
+ "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS,
]);
})

Powered by Google App Engine
This is Rietveld 408576698