| 1 |
// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics |
| 2 |
// Copyright (C) 2018 Amal Hussein. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-atomics.notify |
| 7 |
description: > |
| 8 |
Undefined count arg should result in an infinite count |
| 9 |
info: | |
| 10 |
Atomics.notify( typedArray, index, count ) |
| 11 |
|
| 12 |
3.If count is undefined, let c be +∞. |
| 13 |
|
| 14 |
includes: [atomicsHelper.js] |
| 15 |
features: [Atomics, SharedArrayBuffer, TypedArray] |
| 16 |
---*/ |
| 17 |
|
| 18 |
const RUNNING = 0; // Index to notify agent has started. |
| 19 |
const WAIT_INDEX = 1; // Index all agents are waiting on. |
| 20 |
const BUFFER_SIZE = 2; |
| 21 |
|
| 22 |
const NUMAGENT = 4; // Total number of agents started |
| 23 |
|
| 24 |
for (var i = 0; i < NUMAGENT; i++) { |
| 25 |
$262.agent.start(` |
| 26 |
$262.agent.receiveBroadcast(function(sab) { |
| 27 |
const i32a = new Int32Array(sab); |
| 28 |
Atomics.add(i32a, ${RUNNING}, 1); |
| 29 |
|
| 30 |
// Wait until restarted by main thread. |
| 31 |
var status = Atomics.wait(i32a, ${WAIT_INDEX}, 0); |
| 32 |
|
| 33 |
// Report wait status and then exit the agent. |
| 34 |
var name = String.fromCharCode(0x41 + ${i}); // "A", "B", "C", or "D" |
| 35 |
$262.agent.report(name + " " + status); |
| 36 |
$262.agent.leaving(); |
| 37 |
}); |
| 38 |
`); |
| 39 |
} |
| 40 |
|
| 41 |
const i32a = new Int32Array( |
| 42 |
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE) |
| 43 |
); |
| 44 |
|
| 45 |
$262.agent.safeBroadcast(i32a); |
| 46 |
$262.agent.waitUntil(i32a, RUNNING, NUMAGENT); |
| 47 |
|
| 48 |
// An agent may have been interrupted between reporting its initial report |
| 49 |
// and the `Atomics.wait` call. Try to yield control to ensure the agent |
| 50 |
// actually started to wait. |
| 51 |
$262.agent.tryYield(); |
| 52 |
|
| 53 |
assert.sameValue(Atomics.notify(i32a, WAIT_INDEX, undefined), NUMAGENT, |
| 54 |
'Atomics.notify(i32a, WAIT_INDEX, undefined) returns the value of `NUMAGENT`'); |
| 55 |
|
| 56 |
const reports = []; |
| 57 |
for (var i = 0; i < NUMAGENT; i++) { |
| 58 |
reports.push($262.agent.getReport()); |
| 59 |
} |
| 60 |
reports.sort(); |
| 61 |
|
| 62 |
assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"'); |
| 63 |
assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"'); |
| 64 |
assert.sameValue(reports[2], 'C ok', 'The value of reports[2] is "C ok"'); |
| 65 |
assert.sameValue(reports[3], 'D ok', 'The value of reports[3] is "D ok"'); |
| 66 |
|
| 67 |
reportCompare(0, 0); |