notify-zero.js (1946B)
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) 2017 Mozilla Corporation. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-atomics.notify 7 description: > 8 Test that Atomics.notify notifies zero waiters if that's what the count is. 9 includes: [atomicsHelper.js] 10 features: [Atomics, SharedArrayBuffer, TypedArray] 11 ---*/ 12 13 const WAIT_INDEX = 0; // Agents wait here 14 const RUNNING = 1; // Accounting of live agents here 15 const NOTIFYCOUNT = 0; 16 const NUMAGENT = 3; 17 const BUFFER_SIZE = 4; 18 19 const TIMEOUT = $262.agent.timeouts.long; 20 21 for (var i = 0; i < NUMAGENT; i++) { 22 $262.agent.start(` 23 $262.agent.receiveBroadcast(function(sab) { 24 const i32a = new Int32Array(sab); 25 Atomics.add(i32a, ${RUNNING}, 1); 26 27 // Waiters that are not woken will time out eventually. 28 $262.agent.report(Atomics.wait(i32a, ${WAIT_INDEX}, 0, ${TIMEOUT})); 29 $262.agent.leaving(); 30 }); 31 `); 32 } 33 34 const i32a = new Int32Array( 35 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE) 36 ); 37 38 $262.agent.safeBroadcast(i32a); 39 40 // Wait for agents to be running. 41 $262.agent.waitUntil(i32a, RUNNING, NUMAGENT); 42 43 // Try to yield control to ensure the agent actually started to wait. 44 $262.agent.tryYield(); 45 46 assert.sameValue( 47 Atomics.notify(i32a, WAIT_INDEX, NOTIFYCOUNT), 48 NOTIFYCOUNT, 49 'Atomics.notify(i32a, WAIT_INDEX, NOTIFYCOUNT) returns the value of `NOTIFYCOUNT`' 50 ); 51 52 // Try to sleep past the timeout. 53 $262.agent.trySleep(TIMEOUT); 54 55 for (var i = 0; i < NUMAGENT; i++) { 56 assert.sameValue($262.agent.getReport(), 'timed-out', '$262.agent.getReport() returns "timed-out"'); 57 } 58 59 reportCompare(0, 0);