Atomics

object Atomics(source)

Functions

Link copied to clipboard
external fun <T : JsAny> add(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Adds a value to the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
external fun <T : JsAny> and(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Stores the bitwise AND of a value with the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
external fun <T : JsAny> compareExchange(typedArray: TypedArray<*, *, *, T>, index: Int, expectedValue: T, replacementValue: T): T

Replaces the value at the given position in the array if the original value equals the given expected value, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
external fun <T : JsAny> exchange(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Replaces the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
external fun isLockFree(size: Int): Boolean

Returns a value indicating whether high-performance algorithms can use atomic operations (true) or must use locks (false) for the given number of bytes-per-element of a typed array.

Link copied to clipboard
external fun <T : JsAny> load(typedArray: TypedArray<*, *, *, T>, index: Int): T

Returns the value at the given position in the array. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
external fun notify(typedArray: BigInt64Array<*>, index: Int, count: Int = definedExternally): Int
external fun notify(typedArray: Int32Array<*>, index: Int, count: Int = definedExternally): Int

Wakes up sleeping agents that are waiting on the given index of the array, returning the number of agents that were awoken.

Link copied to clipboard
external fun <T : JsAny> or(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Stores the bitwise OR of a value with the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
external fun pause(n: Int = definedExternally)

Performs a finite-time microwait by signaling to the operating system or CPU that the current executing code is in a spin-wait loop.

Link copied to clipboard
external fun <T : JsAny> store(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Stores a value at the given position in the array, returning the new value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
external fun <T : JsAny> sub(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Subtracts a value from the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.

Link copied to clipboard
external fun wait(typedArray: BigInt64Array<*>, index: Int, value: BigInt, timeout: Int = definedExternally): WaitStatus
external fun wait(typedArray: Int32Array<*>, index: Int, value: Int, timeout: Int = definedExternally): WaitStatus

If the value at the given position in the array is equal to the provided value, the current agent is put to sleep causing execution to suspend until the timeout expires (returning "timed-out") or until the agent is awoken (returning "ok"); otherwise, returns "not-equal".

Link copied to clipboard
external fun waitAsync(typedArray: BigInt64Array<*>, index: Int, value: BigInt, timeout: Int = definedExternally): WaitResult
external fun waitAsync(typedArray: Int32Array<*>, index: Int, value: Int, timeout: Int = definedExternally): WaitResult

A non-blocking, asynchronous version of wait which is usable on the main thread. Waits asynchronously on a shared memory location and returns a Promise

Link copied to clipboard
external fun <T : JsAny> xor(typedArray: TypedArray<*, *, *, T>, index: Int, value: T): T

Stores the bitwise XOR of a value with the value at the given position in the array, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.