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-04-19 16:11:50 +02:00
|
|
|
features: [Atomics, SharedArrayBuffer, TypedArray]
|
2018-03-20 15:40:33 +01:00
|
|
|
---*/
|
|
|
|
|
|
|
|
function getReport() {
|
|
|
|
var r;
|
|
|
|
while ((r = $262.agent.getReport()) == null) {
|
2018-04-25 23:29:53 +02:00
|
|
|
$262.agent.sleep(10);
|
2018-03-20 15:40:33 +01:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
var agent1 = '1';
|
|
|
|
var agent2 = '2';
|
|
|
|
var agent3 = '3';
|
|
|
|
|
2018-04-25 23:29:53 +02:00
|
|
|
$262.agent.start(`
|
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
2018-04-26 17:26:34 +02:00
|
|
|
var i32a = new Int32Array(sab);
|
2018-04-19 16:11:50 +02:00
|
|
|
|
|
|
|
$262.agent.report(${agent1});
|
2018-04-26 17:26:34 +02:00
|
|
|
Atomics.wait(i32a, 0, 0);
|
2018-04-19 16:11:50 +02:00
|
|
|
$262.agent.report(${agent1});
|
|
|
|
|
2018-03-20 15:40:33 +01:00
|
|
|
$262.agent.leaving();
|
2018-04-25 23:29:53 +02:00
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
2018-04-25 23:29:53 +02:00
|
|
|
$262.agent.start(`
|
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
2018-04-26 17:26:34 +02:00
|
|
|
var i32a = new Int32Array(sab);
|
2018-04-19 16:11:50 +02:00
|
|
|
|
2018-03-20 15:40:33 +01:00
|
|
|
$262.agent.report(${agent2});
|
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
Atomics.wait(i32a, 0, 0);
|
2018-03-20 15:40:33 +01:00
|
|
|
$262.agent.report(${agent2});
|
2018-04-19 16:11:50 +02:00
|
|
|
|
2018-03-20 15:40:33 +01:00
|
|
|
$262.agent.leaving();
|
2018-04-25 23:29:53 +02:00
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
2018-04-25 23:29:53 +02:00
|
|
|
$262.agent.start(`
|
|
|
|
$262.agent.receiveBroadcast(function(sab) {
|
2018-04-26 17:26:34 +02:00
|
|
|
var i32a = new Int32Array(sab);
|
2018-04-19 16:11:50 +02:00
|
|
|
|
2018-03-20 15:40:33 +01:00
|
|
|
$262.agent.report(${agent3});
|
2018-04-19 16:11:50 +02:00
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
Atomics.wait(i32a, 0, 0);
|
2018-03-20 15:40:33 +01:00
|
|
|
$262.agent.report(${agent3});
|
2018-04-19 16:11:50 +02:00
|
|
|
|
2018-03-20 15:40:33 +01:00
|
|
|
$262.agent.leaving();
|
2018-04-25 23:29:53 +02:00
|
|
|
});
|
2018-03-20 15:40:33 +01:00
|
|
|
`);
|
|
|
|
|
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
var i32a = new Int32Array(new SharedArrayBuffer(4));
|
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-05-17 20:06:22 +02:00
|
|
|
var orderAgentsStarted = getReport() + getReport() + getReport(); // can be started in any order
|
2018-03-20 15:40:33 +01:00
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
assert.sameValue(Atomics.wake(i32a, 0, 1), 1);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
|
|
|
var orderAgentsWereWoken = getReport();
|
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
assert.sameValue(Atomics.wake(i32a, 0, 1), 1);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
|
|
|
orderAgentsWereWoken += getReport();
|
|
|
|
|
2018-04-26 17:26:34 +02:00
|
|
|
assert.sameValue(Atomics.wake(i32a, 0, 1), 1);
|
2018-03-20 15:40:33 +01:00
|
|
|
|
|
|
|
orderAgentsWereWoken += getReport();
|
|
|
|
|
2018-05-17 20:06:22 +02:00
|
|
|
assert.sameValue(orderAgentsStarted, orderAgentsWereWoken); // agents should wake in the same order as they were started FIFO
|