Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js

raw
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 Rick Waldron. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-atomics.wait
7 description: >
8 Get the correct WaiterList
9 info: |
10 Atomics.wait( typedArray, index, value, timeout )
11
12 ...
13 11. Let WL be GetWaiterList(block, indexedPosition).
14 ...
15
16
17 GetWaiterList( block, i )
18
19 ...
20 4. Return the WaiterList that is referenced by the pair (block, i).
21
22 includes: [atomicsHelper.js]
23 features: [Atomics, SharedArrayBuffer, TypedArray]
24 ---*/
25
26 var NUMAGENT = 2;
27 var RUNNING = 4;
28
29 $262.agent.start(`
30 $262.agent.receiveBroadcast(function(sab) {
31 const i32a = new Int32Array(sab);
32 Atomics.add(i32a, ${RUNNING}, 1);
33
34 // Wait on index 0
35 $262.agent.report(Atomics.wait(i32a, 0, 0, Infinity));
36 $262.agent.leaving();
37 });
38 `);
39
40 $262.agent.start(`
41 $262.agent.receiveBroadcast(function(sab) {
42 const i32a = new Int32Array(sab);
43 Atomics.add(i32a, ${RUNNING}, 1);
44
45 // Wait on index 2
46 $262.agent.report(Atomics.wait(i32a, 2, 0, Infinity));
47 $262.agent.leaving();
48 });
49 `);
50
51 const i32a = new Int32Array(
52 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 5)
53 );
54
55 $262.agent.safeBroadcast(i32a);
56
57 // Wait until all agents started.
58 $262.agent.waitUntil(i32a, RUNNING, NUMAGENT);
59
60 // Notify index 1, notifies nothing
61 assert.sameValue(Atomics.notify(i32a, 1), 0, 'Atomics.notify(i32a, 1) returns 0');
62
63 // Notify index 3, notifies nothing
64 assert.sameValue(Atomics.notify(i32a, 3), 0, 'Atomics.notify(i32a, 3) returns 0');
65
66 // Notify index 2, notifies 1
67 var woken = 0;
68 while ((woken = Atomics.notify(i32a, 2)) === 0) ;
69 assert.sameValue(woken, 1, 'Atomics.notify(i32a, 2) returns 1');
70 assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"');
71
72 // Notify index 0, notifies 1
73 var woken = 0;
74 while ((woken = Atomics.notify(i32a, 0)) === 0) ;
75 assert.sameValue(woken, 1, 'Atomics.notify(i32a, 0) returns 1');
76 assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"');
77
78 reportCompare(0, 0);