Sign in

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

    AtomicsWaitResult

    pub enum AtomicsWaitResult {
    Ok
    NotEqual
    TimedOut
    }

    Wait result returned by wait()

    add

    fn 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)
    add(ta, 0, 12) // returns 0 (the old value)
    load(ta, 0) // 12 (the new value)

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

    and_

    fn 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

    compareExchange

    fn 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)
    store(ta, 0, 5)
    compareExchange(ta, 0, 5, 12) // returns 5
    load(ta, 0) // 12

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

    exchange

    fn 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

    isLockFree

    fn 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

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

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

    load

    fn 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

    notify

    fn 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

    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

    or_

    fn 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

    store

    fn 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

    sub

    fn 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

    wait

    fn 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 = 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

    xor

    fn 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

    Source Files