README

mizchi/js/builtins/atomics does not have a README file

#
Atomics

#external
pub type Atomics

JavaScript Atomics namespace object

#
Atomics::add

fn Atomics::add(typedArray :
Any
, index : Int, value : Int) -> Int

Atomically adds a value to the value at the given position in the array. Returns the old value at that index.

Example

let sab = SharedArrayBuffer::new(1024)
let ta = Uint8Array::new(sab)
Atomics::add(ta, 0, 12) // returns 0 (the old value)
Atomics::load(ta, 0) // 12 (the new value)

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add

#
Atomics::and_

fn Atomics::and_(typedArray :
Any
, index : Int, value : Int) -> Int

Atomically computes a bitwise AND with a value at the given position. Returns the old value at that index.

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and

#
Atomics::compareExchange

fn Atomics::compareExchange(typedArray :
Any
, index : Int, expectedValue : Int, replacementValue : Int) -> Int

Atomically stores a value at the given position, if it equals the expected value. Returns the old value.

Example

let ta = Int32Array::new(sab)
Atomics::store(ta, 0, 5)
Atomics::compareExchange(ta, 0, 5, 12) // returns 5
Atomics::load(ta, 0) // 12

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange

#
Atomics::exchange

fn Atomics::exchange(typedArray :
Any
, index : Int, value : Int) -> Int

Atomically stores a value at the given position in the array. Returns the old value.

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange

#
Atomics::isLockFree

fn Atomics::isLockFree(size : Int) -> Bool

Returns true if an atomic operation on arrays of the given element size will be implemented using a hardware atomic operation (as opposed to a lock).

Example

Atomics::isLockFree(1) // true
Atomics::isLockFree(2) // true
Atomics::isLockFree(4) // true
Atomics::isLockFree(8) // true (on 64-bit systems)

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree

#
Atomics::load

fn Atomics::load(typedArray :
Any
, index : Int) -> Int

Atomically returns the value at the given position in the array.

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load

#
Atomics::notify

fn Atomics::notify(typedArray :
Any
, index : Int, count? : Int) -> Int

Notifies agents waiting on the given index of the array. Returns the number of agents that were notified.

Note: Also known as Atomics.wake() in older specifications.

Example

Atomics::notify(ia, 0, count=1) // Notify 1 agent waiting on index 0

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify

#
Atomics::or_

fn Atomics::or_(typedArray :
Any
, index : Int, value : Int) -> Int

Atomically computes a bitwise OR with a value at the given position. Returns the old value at that index.

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or

#
Atomics::store

fn Atomics::store(typedArray :
Any
, index : Int, value : Int) -> Int

Atomically stores a value at the given position in the array. Returns the value that was stored.

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store

#
Atomics::sub

fn Atomics::sub(typedArray :
Any
, index : Int, value : Int) -> Int

Atomically subtracts a value from the value at the given position. Returns the old value at that index.

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub

#
Atomics::wait

fn Atomics::wait(typedArray :
Any
, index : Int, value : Int, timeout? : Int) -> AtomicsWaitResult

Verifies that the given position in the array still contains a value and sleeps awaiting or times out. Returns Ok, NotEqual, or TimedOut.

Note: This operation is only allowed in workers, not on the main thread.

Example

let result = Atomics::wait(ia, 0, 0, timeout=1000)
match result {
Ok => println("Woken up")
NotEqual => println("Value changed")
TimedOut => println("Timed out")
}

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait

#
Atomics::xor

fn Atomics::xor(typedArray :
Any
, index : Int, value : Int) -> Int

Atomically computes a bitwise XOR with a value at the given position. Returns the old value at that index.

MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor

#
AtomicsWaitResult

pub enum AtomicsWaitResult {
Ok
NotEqual
TimedOut
} derive(Eq)

Wait result returned by wait()

Source Files