Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: test/mjsunit/harmony/futex.js

Issue 2643723010: [d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer) (Closed)
Patch Set: forgot hash_combine Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Flags: --allow-natives-syntax --harmony-sharedarraybuffer 5 // Flags: --allow-natives-syntax --harmony-sharedarraybuffer
6 6
7 (function TestFailsWithNonSharedArray() { 7 (function TestFailsWithNonSharedArray() {
8 var ab = new ArrayBuffer(16); 8 var ab = new ArrayBuffer(16);
9 9
10 var i8a = new Int8Array(ab); 10 var i8a = new Int8Array(ab);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 var i32a = new Int32Array(sab); 113 var i32a = new Int32Array(sab);
114 114
115 var workerScript = 115 var workerScript =
116 `onmessage = function(msg) { 116 `onmessage = function(msg) {
117 var i32a = new Int32Array(msg.sab, msg.offset); 117 var i32a = new Int32Array(msg.sab, msg.offset);
118 var result = Atomics.wait(i32a, 0, 0, ${timeout}); 118 var result = Atomics.wait(i32a, 0, 0, ${timeout});
119 postMessage(result); 119 postMessage(result);
120 };`; 120 };`;
121 121
122 var worker = new Worker(workerScript); 122 var worker = new Worker(workerScript);
123 worker.postMessage({sab: sab, offset: offset}, [sab]); 123 worker.postMessage({sab: sab, offset: offset});
124 124
125 // Spin until the worker is waiting on the futex. 125 // Spin until the worker is waiting on the futex.
126 while (%AtomicsNumWaitersForTesting(i32a, 0) != 1) {} 126 while (%AtomicsNumWaitersForTesting(i32a, 0) != 1) {}
127 127
128 Atomics.wake(i32a, 0, 1); 128 Atomics.wake(i32a, 0, 1);
129 assertEquals("ok", worker.getMessage()); 129 assertEquals("ok", worker.getMessage());
130 worker.terminate(); 130 worker.terminate();
131 131
132 var worker2 = new Worker(workerScript); 132 var worker2 = new Worker(workerScript);
133 var offset = 8; 133 var offset = 8;
134 var i32a2 = new Int32Array(sab, offset); 134 var i32a2 = new Int32Array(sab, offset);
135 worker2.postMessage({sab: sab, offset: offset}, [sab]); 135 worker2.postMessage({sab: sab, offset: offset});
136 136
137 // Spin until the worker is waiting on the futex. 137 // Spin until the worker is waiting on the futex.
138 while (%AtomicsNumWaitersForTesting(i32a2, 0) != 1) {} 138 while (%AtomicsNumWaitersForTesting(i32a2, 0) != 1) {}
139 Atomics.wake(i32a2, 0, 1); 139 Atomics.wake(i32a2, 0, 1);
140 assertEquals("ok", worker2.getMessage()); 140 assertEquals("ok", worker2.getMessage());
141 worker2.terminate(); 141 worker2.terminate();
142 142
143 // Futex should work when index and buffer views are different, but 143 // Futex should work when index and buffer views are different, but
144 // the real address is the same. 144 // the real address is the same.
145 var worker3 = new Worker(workerScript); 145 var worker3 = new Worker(workerScript);
146 i32a2 = new Int32Array(sab, 4); 146 i32a2 = new Int32Array(sab, 4);
147 worker3.postMessage({sab: sab, offset: 8}, [sab]); 147 worker3.postMessage({sab: sab, offset: 8});
148 148
149 // Spin until the worker is waiting on the futex. 149 // Spin until the worker is waiting on the futex.
150 while (%AtomicsNumWaitersForTesting(i32a2, 1) != 1) {} 150 while (%AtomicsNumWaitersForTesting(i32a2, 1) != 1) {}
151 Atomics.wake(i32a2, 1, 1); 151 Atomics.wake(i32a2, 1, 1);
152 assertEquals("ok", worker3.getMessage()); 152 assertEquals("ok", worker3.getMessage());
153 worker3.terminate(); 153 worker3.terminate();
154 }; 154 };
155 155
156 // Test various infinite timeouts 156 // Test various infinite timeouts
157 TestWaitWithTimeout(undefined); 157 TestWaitWithTimeout(undefined);
(...skipping 25 matching lines...) Expand all
183 // Set i32a[id] to 1 to notify the main thread which workers were 183 // Set i32a[id] to 1 to notify the main thread which workers were
184 // woken up. 184 // woken up.
185 Atomics.store(i32a, id, 1); 185 Atomics.store(i32a, id, 1);
186 postMessage(result); 186 postMessage(result);
187 };`; 187 };`;
188 188
189 var id; 189 var id;
190 var workers = []; 190 var workers = [];
191 for (id = 0; id < 4; id++) { 191 for (id = 0; id < 4; id++) {
192 workers[id] = new Worker(workerScript); 192 workers[id] = new Worker(workerScript);
193 workers[id].postMessage({sab: sab, id: id}, [sab]); 193 workers[id].postMessage({sab: sab, id: id});
194 } 194 }
195 195
196 // Spin until all workers are waiting on the futex. 196 // Spin until all workers are waiting on the futex.
197 while (%AtomicsNumWaitersForTesting(i32a, 4) != 4) {} 197 while (%AtomicsNumWaitersForTesting(i32a, 4) != 4) {}
198 198
199 // Wake up three waiters. 199 // Wake up three waiters.
200 assertEquals(3, Atomics.wake(i32a, 4, 3)); 200 assertEquals(3, Atomics.wake(i32a, 4, 3));
201 201
202 var wokenCount = 0; 202 var wokenCount = 0;
203 var waitingId = 0 + 1 + 2 + 3; 203 var waitingId = 0 + 1 + 2 + 3;
(...skipping 17 matching lines...) Expand all
221 // Finally wake the last waiter. 221 // Finally wake the last waiter.
222 assertEquals(1, Atomics.wake(i32a, 4, 1)); 222 assertEquals(1, Atomics.wake(i32a, 4, 1));
223 assertEquals("ok", workers[waitingId].getMessage()); 223 assertEquals("ok", workers[waitingId].getMessage());
224 workers[waitingId].terminate(); 224 workers[waitingId].terminate();
225 225
226 assertEquals(0, %AtomicsNumWaitersForTesting(i32a, 4)); 226 assertEquals(0, %AtomicsNumWaitersForTesting(i32a, 4));
227 227
228 })(); 228 })();
229 229
230 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698