2018-03-20 15:40:33 +01:00
|
|
|
// Copyright (C) 2018 Amal Hussein. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
|
|
|
|
/*---
|
|
|
|
esid: sec-atomics.wake
|
|
|
|
description: >
|
|
|
|
Undefined count arg should result in an infinite count
|
|
|
|
info: |
|
|
|
|
Atomics.wake( typedArray, index, count )
|
|
|
|
|
|
|
|
3.If count is undefined, let c be +∞.
|
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
includes: [atomicsHelper.js]
|
2018-04-19 16:11:50 +02:00
|
|
|
features: [Atomics, SharedArrayBuffer, TypedArray]
|
2018-03-20 15:40:33 +01:00
|
|
|
---*/
|
|
|
|
|
2018-06-26 20:40:00 +02:00
|
|
|
const RUNNING = 0
|
|
|
|
const WAIT_INDEX = 1; // Index all agents are waiting on
|
2018-05-21 20:23:15 +02:00
|
|
|
const NUMAGENT = 4; // Total number of agents started
|
2018-06-26 20:40:00 +02:00
|
|
|
const BUFFER_SIZE = 5; // Index all agents are waiting on
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-04-25 16:00:35 +02:00
|
|
|
$262.agent.start(`
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
2018-06-26 20:40:00 +02:00
|
|
|
Atomics.add(i32a, ${RUNNING}, 1);
|
|
|
|
$262.agent.report("A " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50));
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
2018-04-25 16:00:35 +02:00
|
|
|
$262.agent.start(`
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
2018-06-26 20:40:00 +02:00
|
|
|
Atomics.add(i32a, ${RUNNING}, 1);
|
|
|
|
$262.agent.report("B " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50));
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
2018-04-25 16:00:35 +02:00
|
|
|
$262.agent.start(`
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
2018-06-26 20:40:00 +02:00
|
|
|
Atomics.add(i32a, ${RUNNING}, 1);
|
|
|
|
$262.agent.report("C " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50));
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
2018-04-25 16:00:35 +02:00
|
|
|
$262.agent.start(`
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
2018-06-26 20:40:00 +02:00
|
|
|
Atomics.add(i32a, ${RUNNING}, 1);
|
|
|
|
$262.agent.report("D " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50));
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
const i32a = new Int32Array(
|
2018-06-26 20:40:00 +02:00
|
|
|
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE)
|
2018-05-21 20:23:15 +02:00
|
|
|
);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
$262.agent.broadcast(i32a.buffer);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-06-26 20:40:00 +02:00
|
|
|
// Wait for agents to be running.
|
2018-06-27 17:13:23 +02:00
|
|
|
$262.agent.waitUntil(i32a, RUNNING, NUMAGENT);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
assert.sameValue(
|
2018-06-26 20:40:00 +02:00
|
|
|
Atomics.wake(i32a, WAIT_INDEX, undefined),
|
2018-05-21 20:23:15 +02:00
|
|
|
NUMAGENT,
|
2018-06-27 18:58:02 +02:00
|
|
|
'Atomics.wake(i32a, WAIT_INDEX, undefined) returns the value of `NUMAGENT` (4)'
|
2018-05-21 20:23:15 +02:00
|
|
|
);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-06-27 17:13:23 +02:00
|
|
|
const reports = [];
|
2018-03-20 15:40:33 +01:00
|
|
|
for (var i = 0; i < NUMAGENT; i++) {
|
2018-06-27 17:13:23 +02:00
|
|
|
reports.push($262.agent.getReport());
|
2018-03-20 15:40:33 +01:00
|
|
|
}
|
2018-06-27 17:13:23 +02:00
|
|
|
reports.sort();
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-06-27 17:13:23 +02:00
|
|
|
assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"');
|
|
|
|
assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"');
|
|
|
|
assert.sameValue(reports[2], 'C ok', 'The value of reports[2] is "C ok"');
|
|
|
|
assert.sameValue(reports[3], 'D ok', 'The value of reports[3] is "D ok"');
|