waiterlist-block-indexedposition-wake.js (2365B)
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, BigInt, SharedArrayBuffer, TypedArray] 24 ---*/ 25 26 var NUMAGENT = 2; 27 var RUNNING = 4; 28 29 const i64a = new BigInt64Array( 30 new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5) 31 ); 32 33 $262.agent.start(` 34 $262.agent.receiveBroadcast(function(sab) { 35 const i64a = new BigInt64Array(sab); 36 Atomics.add(i64a, ${RUNNING}, 1n); 37 38 // Wait on index 0 39 $262.agent.report(Atomics.wait(i64a, 0, 0n, Infinity)); 40 $262.agent.leaving(); 41 }); 42 `); 43 44 $262.agent.start(` 45 $262.agent.receiveBroadcast(function(sab) { 46 const i64a = new BigInt64Array(sab); 47 Atomics.add(i64a, ${RUNNING}, 1n); 48 49 // Wait on index 2 50 $262.agent.report(Atomics.wait(i64a, 2, 0n, Infinity)); 51 $262.agent.leaving(); 52 }); 53 `); 54 55 $262.agent.safeBroadcast(i64a); 56 57 // Wait until all agents started. 58 $262.agent.waitUntil(i64a, RUNNING, BigInt(NUMAGENT)); 59 60 // Notify index 1, notifies nothing 61 assert.sameValue(Atomics.notify(i64a, 1), 0, 'Atomics.notify(i64a, 1) returns 0'); 62 63 // Notify index 3, notifies nothing 64 assert.sameValue(Atomics.notify(i64a, 3), 0, 'Atomics.notify(i64a, 3) returns 0'); 65 66 // Notify index 2, notifies 1 67 var woken = 0; 68 while ((woken = Atomics.notify(i64a, 2)) === 0) ; 69 assert.sameValue(woken, 1, 'Atomics.notify(i64a, 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(i64a, 0)) === 0) ; 75 assert.sameValue(woken, 1, 'Atomics.notify(i64a, 0) returns 1'); 76 assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"'); 77 78 reportCompare(0, 0);