ISharedDataBlockWaiters Interface

The waiters of a shared data block whose memory is shared with a WebAssembly runtime (the bytes of a shared WebAssembly.Memory), which Atomics.wait, Atomics.waitAsync and Atomics.notify use instead of the waiters of the script engine (see IGrowableSharedDataBlock.SetWaiters): they notify the waiters of the memory.atomic.wait32 and memory.atomic.wait64 instructions, and are notified by the memory.atomic.notify instruction.

public interface ISharedDataBlockWaiters

Methods

NameDescription
Notify(int, int)Notifies the waiters of a location of the block (Atomics.notify), and returns the number of waiters notified.
Wait(int, long, int, TimeSpan?, CancellationToken)Blocks the calling thread until the waiter of a location of the block is notified, when the location contains expectedValue (Atomics.wait). A location that no longer contains the expected value completes the wait as a notification (the script engine checked the value before).
WaitAsync(int, long, int, TimeSpan?, Action<bool>, CancellationToken)Adds an asynchronous waiter of a location of the block (Atomics.waitAsync), when the location contains expectedValue: it is added when the method returns, so that a notification that follows notifies it. completed is called once, on any thread: with true when the waiter was notified (or when the location no longer contained the expected value), and with false when the wait timed out or was canceled.

Notify(int, int)

Notifies the waiters of a location of the block (Atomics.notify), and returns the number of waiters notified.

int Notify(int byteIndex, int count)

Parameters

byteIndex int
The index of the location in the block: a multiple of 4 within the block.
count int
The maximum number of waiters to notify; Int32.MaxValue notifies all of them.

Returns

int

Wait(int, long, int, TimeSpan?, CancellationToken)

Blocks the calling thread until the waiter of a location of the block is notified, when the location contains expectedValue (Atomics.wait). A location that no longer contains the expected value completes the wait as a notification (the script engine checked the value before).

bool Wait(int byteIndex, long expectedValue, int size, TimeSpan? timeout, CancellationToken cancellationToken)

Parameters

byteIndex int
The index of the location in the block: a multiple of size within the block.
expectedValue long
The expected value of the location (sign-extended for a 32-bit location).
size int
The size of the location in bytes: 4 or 8.
timeout TimeSpan?
The maximum duration of the wait, or null to wait until notified.
cancellationToken CancellationToken
A token that stops the wait.

Returns

bool true when the waiter was notified; false when the wait timed out or was canceled.

WaitAsync(int, long, int, TimeSpan?, Action<bool>, CancellationToken)

Adds an asynchronous waiter of a location of the block (Atomics.waitAsync), when the location contains expectedValue: it is added when the method returns, so that a notification that follows notifies it. completed is called once, on any thread: with true when the waiter was notified (or when the location no longer contained the expected value), and with false when the wait timed out or was canceled.

bool WaitAsync(int byteIndex, long expectedValue, int size, TimeSpan? timeout, Action<bool> completed, CancellationToken cancellationToken)

Parameters

byteIndex int
The index of the location in the block: a multiple of size within the block.
expectedValue long
The expected value of the location (sign-extended for a 32-bit location).
size int
The size of the location in bytes: 4 or 8.
timeout TimeSpan?
The maximum duration of the wait, or null to wait until notified.
completed Action<bool>
The callback called when the wait completes.
cancellationToken CancellationToken
A token that stops the wait (the agent of the waiter stops).

Returns

bool true when the waiter is added; false when the runtime cannot add more waiters (completed is then not called).