UNPKG

6.35 kBTypeScriptView Raw
1/*! *****************************************************************************
2Copyright (c) Microsoft Corporation. All rights reserved.
3Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4this file except in compliance with the License. You may obtain a copy of the
5License at http://www.apache.org/licenses/LICENSE-2.0
6
7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10MERCHANTABLITY OR NON-INFRINGEMENT.
11
12See the Apache Version 2.0 License for specific language governing permissions
13and limitations under the License.
14***************************************************************************** */
15
16
17
18/// <reference no-default-lib="true"/>
19
20
21/// <reference lib="es2015.symbol" />
22/// <reference lib="es2015.symbol.wellknown" />
23
24interface SharedArrayBuffer {
25 /**
26 * Read-only. The length of the ArrayBuffer (in bytes).
27 */
28 readonly byteLength: number;
29
30 /**
31 * Returns a section of an SharedArrayBuffer.
32 */
33 slice(begin: number, end?: number): SharedArrayBuffer;
34 readonly [Symbol.species]: SharedArrayBuffer;
35 readonly [Symbol.toStringTag]: "SharedArrayBuffer";
36}
37
38interface SharedArrayBufferConstructor {
39 readonly prototype: SharedArrayBuffer;
40 new (byteLength: number): SharedArrayBuffer;
41}
42declare var SharedArrayBuffer: SharedArrayBufferConstructor;
43
44interface ArrayBufferTypes {
45 SharedArrayBuffer: SharedArrayBuffer;
46}
47
48interface Atomics {
49 /**
50 * Adds a value to the value at the given position in the array, returning the original value.
51 * Until this atomic operation completes, any other read or write operation against the array
52 * will block.
53 */
54 add(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
55
56 /**
57 * Stores the bitwise AND of a value with the value at the given position in the array,
58 * returning the original value. Until this atomic operation completes, any other read or
59 * write operation against the array will block.
60 */
61 and(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
62
63 /**
64 * Replaces the value at the given position in the array if the original value equals the given
65 * expected value, returning the original value. Until this atomic operation completes, any
66 * other read or write operation against the array will block.
67 */
68 compareExchange(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, expectedValue: number, replacementValue: number): number;
69
70 /**
71 * Replaces the value at the given position in the array, returning the original value. Until
72 * this atomic operation completes, any other read or write operation against the array will
73 * block.
74 */
75 exchange(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
76
77 /**
78 * Returns a value indicating whether high-performance algorithms can use atomic operations
79 * (`true`) or must use locks (`false`) for the given number of bytes-per-element of a typed
80 * array.
81 */
82 isLockFree(size: number): boolean;
83
84 /**
85 * Returns the value at the given position in the array. Until this atomic operation completes,
86 * any other read or write operation against the array will block.
87 */
88 load(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number): number;
89
90 /**
91 * Stores the bitwise OR of a value with the value at the given position in the array,
92 * returning the original value. Until this atomic operation completes, any other read or write
93 * operation against the array will block.
94 */
95 or(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
96
97 /**
98 * Stores a value at the given position in the array, returning the new value. Until this
99 * atomic operation completes, any other read or write operation against the array will block.
100 */
101 store(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
102
103 /**
104 * Subtracts a value from the value at the given position in the array, returning the original
105 * value. Until this atomic operation completes, any other read or write operation against the
106 * array will block.
107 */
108 sub(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
109
110 /**
111 * If the value at the given position in the array is equal to the provided value, the current
112 * agent is put to sleep causing execution to suspend until the timeout expires (returning
113 * `"timed-out"`) or until the agent is awoken (returning `"ok"`); otherwise, returns
114 * `"not-equal"`.
115 */
116 wait(typedArray: Int32Array, index: number, value: number, timeout?: number): "ok" | "not-equal" | "timed-out";
117
118 /**
119 * Wakes up sleeping agents that are waiting on the given index of the array, returning the
120 * number of agents that were awoken.
121 * @param typedArray A shared Int32Array.
122 * @param index The position in the typedArray to wake up on.
123 * @param count The number of sleeping agents to notify. Defaults to +Infinity.
124 */
125 notify(typedArray: Int32Array, index: number, count?: number): number;
126
127 /**
128 * Stores the bitwise XOR of a value with the value at the given position in the array,
129 * returning the original value. Until this atomic operation completes, any other read or write
130 * operation against the array will block.
131 */
132 xor(typedArray: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array, index: number, value: number): number;
133
134 readonly [Symbol.toStringTag]: "Atomics";
135}
136
137declare var Atomics: Atomics;