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 ISharedDataBlockWaitersMethods
| Name | Description |
|---|---|
| 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.
Parameters
byteIndexint- The index of the location in the block: a multiple of 4 within the block.
countint- The maximum number of waiters to notify;
Int32.MaxValuenotifies all of them.
Returns
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
byteIndexint- The index of the location in the block: a multiple of
sizewithin the block. expectedValuelong- The expected value of the location (sign-extended for a 32-bit location).
sizeint- The size of the location in bytes: 4 or 8.
timeoutTimeSpan?- The maximum duration of the wait, or
nullto wait until notified. cancellationTokenCancellationToken- 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
byteIndexint- The index of the location in the block: a multiple of
sizewithin the block. expectedValuelong- The expected value of the location (sign-extended for a 32-bit location).
sizeint- The size of the location in bytes: 4 or 8.
timeoutTimeSpan?- The maximum duration of the wait, or
nullto wait until notified. completedAction<bool>- The callback called when the wait completes.
cancellationTokenCancellationToken- 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).