2017-02-07 17:17:31 +01:00
|
|
|
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
|
|
|
|
/*---
|
2017-07-26 23:49:55 +02:00
|
|
|
esid: sec-atomics.wake
|
2017-02-07 17:17:31 +01:00
|
|
|
description: >
|
|
|
|
Test that Atomics.wake wakes zero waiters if that's what the count is.
|
2018-05-21 20:23:15 +02:00
|
|
|
includes: [atomicsHelper.js]
|
2018-04-19 16:11:50 +02:00
|
|
|
features: [Atomics, SharedArrayBuffer, TypedArray]
|
2017-02-07 17:17:31 +01:00
|
|
|
---*/
|
|
|
|
|
2018-06-26 19:22:30 +02:00
|
|
|
const WAKECOUNT = 0;
|
|
|
|
const WAIT_INDEX = 0; // Agents wait here
|
|
|
|
const RUNNING = 1; // Accounting of live agents here
|
|
|
|
const NUMAGENT = 3;
|
|
|
|
const BUFFER_SIZE = 4;
|
2017-10-17 15:56:52 +02:00
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
for (var i = 0; i < NUMAGENT; i++) {
|
2018-06-26 19:22:30 +02:00
|
|
|
$262.agent.start(`
|
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
|
|
|
Atomics.add(i32a, ${RUNNING}, 1);
|
|
|
|
// Waiters that are not woken will time out eventually.
|
|
|
|
$262.agent.report(Atomics.wait(i32a, ${WAIT_INDEX}, 0, 200));
|
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
|
|
|
`);
|
2017-10-17 15:56:52 +02:00
|
|
|
}
|
2017-02-07 17:17:31 +01:00
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
const i32a = new Int32Array(
|
2018-06-26 19:22:30 +02:00
|
|
|
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE)
|
2018-05-21 20:23:15 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$262.agent.broadcast(i32a.buffer);
|
|
|
|
|
2017-10-17 15:56:52 +02:00
|
|
|
// Wait for agents to be running.
|
2018-05-21 20:23:15 +02:00
|
|
|
waitUntil(i32a, RUNNING, NUMAGENT);
|
2017-10-17 15:56:52 +02:00
|
|
|
|
|
|
|
// There's a slight risk we'll fail to wake the desired count, if the preceding
|
|
|
|
// sleep() took much longer than anticipated and workers have started timing
|
|
|
|
// out.
|
2018-05-21 20:23:15 +02:00
|
|
|
assert.sameValue(
|
2018-06-26 19:22:30 +02:00
|
|
|
Atomics.wake(i32a, WAIT_INDEX, WAKECOUNT),
|
2018-05-21 20:23:15 +02:00
|
|
|
WAKECOUNT,
|
2018-06-26 19:22:30 +02:00
|
|
|
'Atomics.wake(i32a, WAIT_INDEX, WAKECOUNT) equals the value of `WAKECOUNT` (0)'
|
2018-05-21 20:23:15 +02:00
|
|
|
);
|
2017-10-17 15:56:52 +02:00
|
|
|
|
2018-06-26 19:22:30 +02:00
|
|
|
// Sleep past the timeout
|
|
|
|
$262.agent.sleep(300);
|
2017-10-17 15:56:52 +02:00
|
|
|
|
2018-06-26 19:22:30 +02:00
|
|
|
for (var i = 0; i < NUMAGENT; i++) {
|
|
|
|
assert.sameValue(getReport(), 'timed-out', `Report #${i}: must equal "timed-out"`);
|
2018-04-19 16:11:50 +02:00
|
|
|
}
|