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.wait
|
|
|
|
description: >
|
|
|
|
New waiters should be applied to the end of the list and woken by order they entered the list (FIFO)
|
|
|
|
info: |
|
|
|
|
Atomics.wait( typedArray, index, value, timeout )
|
|
|
|
|
|
|
|
16.Perform AddWaiter(WL, W).
|
|
|
|
...
|
|
|
|
3.Add W to the end of the list of waiters in WL.
|
|
|
|
|
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-05-21 20:23:15 +02:00
|
|
|
var agent1 = '1';
|
|
|
|
var agent2 = '2';
|
|
|
|
var agent3 = '3';
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-04-25 23:29:53 +02:00
|
|
|
$262.agent.start(`
|
2018-05-19 02:52:31 +02:00
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
|
|
|
|
|
|
|
$262.agent.report(${agent1});
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.report(Atomics.wait(i32a, 1, 0));
|
2018-05-19 02:52:31 +02:00
|
|
|
$262.agent.report(${agent1});
|
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
2018-04-25 23:29:53 +02:00
|
|
|
$262.agent.start(`
|
2018-05-19 02:52:31 +02:00
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
|
|
|
|
|
|
|
$262.agent.report(${agent2});
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.report(Atomics.wait(i32a, 2, 0));
|
2018-05-19 02:52:31 +02:00
|
|
|
$262.agent.report(${agent2});
|
|
|
|
$262.agent.leaving();
|
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
2018-04-25 23:29:53 +02:00
|
|
|
$262.agent.start(`
|
2018-05-19 02:52:31 +02:00
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
|
|
|
const i32a = new Int32Array(sab);
|
|
|
|
|
|
|
|
$262.agent.report(${agent3});
|
2018-05-21 20:23:15 +02:00
|
|
|
$262.agent.report(Atomics.wait(i32a, 3, 0));
|
2018-05-19 02:52:31 +02:00
|
|
|
$262.agent.report(${agent3});
|
|
|
|
$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-25 21:17:45 +02:00
|
|
|
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
|
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-06-25 23:02:58 +02:00
|
|
|
$262.agent.sleep(100);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
// Agents may be started in any order...
|
2018-06-27 17:13:23 +02:00
|
|
|
const started = [$262.agent.getReport(), $262.agent.getReport(), $262.agent.getReport()];
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-05-21 20:23:15 +02:00
|
|
|
// Agents must wake in the order they waited
|
2018-06-27 18:58:02 +02:00
|
|
|
assert.sameValue(Atomics.wake(i32a, 1, 1), 1, 'Atomics.wake(i32a, 1, 1) returns 1');
|
|
|
|
assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"');
|
|
|
|
assert.sameValue(
|
|
|
|
$262.agent.getReport(),
|
|
|
|
started[0],
|
|
|
|
'$262.agent.getReport() returns the value of `started[0]` (undefined)'
|
|
|
|
);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-06-27 18:58:02 +02:00
|
|
|
assert.sameValue(Atomics.wake(i32a, 2, 1), 1, 'Atomics.wake(i32a, 2, 1) returns 1');
|
|
|
|
assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"');
|
|
|
|
assert.sameValue(
|
|
|
|
$262.agent.getReport(),
|
|
|
|
started[1],
|
|
|
|
'$262.agent.getReport() returns the value of `started[1]` (undefined)'
|
|
|
|
);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-06-27 18:58:02 +02:00
|
|
|
assert.sameValue(Atomics.wake(i32a, 3, 1), 1, 'Atomics.wake(i32a, 3, 1) returns 1');
|
|
|
|
assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"');
|
|
|
|
assert.sameValue(
|
|
|
|
$262.agent.getReport(),
|
|
|
|
started[2],
|
|
|
|
'$262.agent.getReport() returns the value of `started[2]` (undefined)'
|
|
|
|
);
|