OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 CheckSharedIntegerTypedArray(ia); | 101 CheckSharedIntegerTypedArray(ia); |
102 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); | 102 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); |
103 value = TO_NUMBER(value); | 103 value = TO_NUMBER(value); |
104 return %_AtomicsExchange(ia, index, value); | 104 return %_AtomicsExchange(ia, index, value); |
105 } | 105 } |
106 | 106 |
107 function AtomicsIsLockFreeJS(size) { | 107 function AtomicsIsLockFreeJS(size) { |
108 return %_AtomicsIsLockFree(size); | 108 return %_AtomicsIsLockFree(size); |
109 } | 109 } |
110 | 110 |
111 // Futexes | 111 function AtomicsWaitJS(ia, index, value, timeout) { |
112 | |
113 function AtomicsFutexWaitJS(ia, index, value, timeout) { | |
114 CheckSharedInteger32TypedArray(ia); | 112 CheckSharedInteger32TypedArray(ia); |
115 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); | 113 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); |
116 if (IS_UNDEFINED(timeout)) { | 114 if (IS_UNDEFINED(timeout)) { |
117 timeout = INFINITY; | 115 timeout = INFINITY; |
118 } else { | 116 } else { |
119 timeout = TO_NUMBER(timeout); | 117 timeout = TO_NUMBER(timeout); |
120 if (NUMBER_IS_NAN(timeout)) { | 118 if (NUMBER_IS_NAN(timeout)) { |
121 timeout = INFINITY; | 119 timeout = INFINITY; |
122 } else { | 120 } else { |
123 timeout = MaxSimple(0, timeout); | 121 timeout = MaxSimple(0, timeout); |
124 } | 122 } |
125 } | 123 } |
126 return %AtomicsFutexWait(ia, index, value, timeout); | 124 return %AtomicsWait(ia, index, value, timeout); |
127 } | 125 } |
128 | 126 |
129 function AtomicsFutexWakeJS(ia, index, count) { | 127 function AtomicsWakeJS(ia, index, count) { |
130 CheckSharedInteger32TypedArray(ia); | 128 CheckSharedInteger32TypedArray(ia); |
131 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); | 129 index = ValidateIndex(index, %_TypedArrayGetLength(ia)); |
132 count = MaxSimple(0, TO_INTEGER(count)); | 130 count = MaxSimple(0, TO_INTEGER(count)); |
133 return %AtomicsFutexWake(ia, index, count); | 131 return %AtomicsWake(ia, index, count); |
134 } | |
135 | |
136 function AtomicsFutexWakeOrRequeueJS(ia, index1, count, value, index2) { | |
137 CheckSharedInteger32TypedArray(ia); | |
138 index1 = ValidateIndex(index1, %_TypedArrayGetLength(ia)); | |
139 count = MaxSimple(0, TO_INTEGER(count)); | |
140 value = TO_INT32(value); | |
141 index2 = ValidateIndex(index2, %_TypedArrayGetLength(ia)); | |
142 if (index1 < 0 || index1 >= %_TypedArrayGetLength(ia) || | |
143 index2 < 0 || index2 >= %_TypedArrayGetLength(ia)) { | |
144 return UNDEFINED; | |
145 } | |
146 return %AtomicsFutexWakeOrRequeue(ia, index1, count, value, index2); | |
147 } | 132 } |
148 | 133 |
149 // ------------------------------------------------------------------- | 134 // ------------------------------------------------------------------- |
150 | 135 |
151 var Atomics = global.Atomics; | 136 var Atomics = global.Atomics; |
152 | 137 |
153 // The Atomics global is defined by the bootstrapper. | 138 // The Atomics global is defined by the bootstrapper. |
154 | 139 |
155 %AddNamedProperty(Atomics, toStringTagSymbol, "Atomics", READ_ONLY | DONT_ENUM); | 140 %AddNamedProperty(Atomics, toStringTagSymbol, "Atomics", READ_ONLY | DONT_ENUM); |
156 | 141 |
157 // These must match the values in src/futex-emulation.h | |
158 utils.InstallConstants(Atomics, [ | |
159 "OK", 0, | |
160 "NOTEQUAL", -1, | |
161 "TIMEDOUT", -2, | |
162 ]); | |
163 | |
164 utils.InstallFunctions(Atomics, DONT_ENUM, [ | 142 utils.InstallFunctions(Atomics, DONT_ENUM, [ |
165 // TODO(binji): remove the rest of the (non futex) Atomics functions as they | 143 // TODO(binji): remove the rest of the (non futex) Atomics functions as they |
166 // become builtins. | 144 // become builtins. |
167 "compareExchange", AtomicsCompareExchangeJS, | 145 "compareExchange", AtomicsCompareExchangeJS, |
168 "add", AtomicsAddJS, | 146 "add", AtomicsAddJS, |
169 "sub", AtomicsSubJS, | 147 "sub", AtomicsSubJS, |
170 "and", AtomicsAndJS, | 148 "and", AtomicsAndJS, |
171 "or", AtomicsOrJS, | 149 "or", AtomicsOrJS, |
172 "xor", AtomicsXorJS, | 150 "xor", AtomicsXorJS, |
173 "exchange", AtomicsExchangeJS, | 151 "exchange", AtomicsExchangeJS, |
174 "isLockFree", AtomicsIsLockFreeJS, | 152 "isLockFree", AtomicsIsLockFreeJS, |
175 "futexWait", AtomicsFutexWaitJS, | 153 "wait", AtomicsWaitJS, |
176 "futexWake", AtomicsFutexWakeJS, | 154 "wake", AtomicsWakeJS, |
177 "futexWakeOrRequeue", AtomicsFutexWakeOrRequeueJS, | |
178 ]); | 155 ]); |
179 | 156 |
180 }) | 157 }) |
OLD | NEW |