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

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

Issue 2643723010: [d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer) (Closed)
Patch Set: Exit(1) Created 3 years, 11 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 var i32a = new Int32Array(sab); 104 var i32a = new Int32Array(sab);
105 105
106 var workerScript = 106 var workerScript =
107 `onmessage = function(msg) { 107 `onmessage = function(msg) {
108 var i32a = new Int32Array(msg.sab, msg.offset); 108 var i32a = new Int32Array(msg.sab, msg.offset);
109 var result = Atomics.wait(i32a, 0, 0, ${timeout}); 109 var result = Atomics.wait(i32a, 0, 0, ${timeout});
110 postMessage(result); 110 postMessage(result);
111 };`; 111 };`;
112 112
113 var worker = new Worker(workerScript); 113 var worker = new Worker(workerScript);
114 worker.postMessage({sab: sab, offset: offset}, [sab]); 114 worker.postMessage({sab: sab, offset: offset});
115 115
116 // Spin until the worker is waiting on the futex. 116 // Spin until the worker is waiting on the futex.
117 while (%AtomicsNumWaitersForTesting(i32a, 0) != 1) {} 117 while (%AtomicsNumWaitersForTesting(i32a, 0) != 1) {}
118 118
119 Atomics.wake(i32a, 0, 1); 119 Atomics.wake(i32a, 0, 1);
120 assertEquals("ok", worker.getMessage()); 120 assertEquals("ok", worker.getMessage());
121 worker.terminate(); 121 worker.terminate();
122 122
123 var worker2 = new Worker(workerScript); 123 var worker2 = new Worker(workerScript);
124 var offset = 8; 124 var offset = 8;
125 var i32a2 = new Int32Array(sab, offset); 125 var i32a2 = new Int32Array(sab, offset);
126 worker2.postMessage({sab: sab, offset: offset}, [sab]); 126 worker2.postMessage({sab: sab, offset: offset});
127 127
128 // Spin until the worker is waiting on the futex. 128 // Spin until the worker is waiting on the futex.
129 while (%AtomicsNumWaitersForTesting(i32a2, 0) != 1) {} 129 while (%AtomicsNumWaitersForTesting(i32a2, 0) != 1) {}
130 Atomics.wake(i32a2, 0, 1); 130 Atomics.wake(i32a2, 0, 1);
131 assertEquals("ok", worker2.getMessage()); 131 assertEquals("ok", worker2.getMessage());
132 worker2.terminate(); 132 worker2.terminate();
133 133
134 // Futex should work when index and buffer views are different, but 134 // Futex should work when index and buffer views are different, but
135 // the real address is the same. 135 // the real address is the same.
136 var worker3 = new Worker(workerScript); 136 var worker3 = new Worker(workerScript);
137 i32a2 = new Int32Array(sab, 4); 137 i32a2 = new Int32Array(sab, 4);
138 worker3.postMessage({sab: sab, offset: 8}, [sab]); 138 worker3.postMessage({sab: sab, offset: 8});
139 139
140 // Spin until the worker is waiting on the futex. 140 // Spin until the worker is waiting on the futex.
141 while (%AtomicsNumWaitersForTesting(i32a2, 1) != 1) {} 141 while (%AtomicsNumWaitersForTesting(i32a2, 1) != 1) {}
142 Atomics.wake(i32a2, 1, 1); 142 Atomics.wake(i32a2, 1, 1);
143 assertEquals("ok", worker3.getMessage()); 143 assertEquals("ok", worker3.getMessage());
144 worker3.terminate(); 144 worker3.terminate();
145 }; 145 };
146 146
147 // Test various infinite timeouts 147 // Test various infinite timeouts
148 TestWaitWithTimeout(undefined); 148 TestWaitWithTimeout(undefined);
(...skipping 25 matching lines...) Expand all
174 // Set i32a[id] to 1 to notify the main thread which workers were 174 // Set i32a[id] to 1 to notify the main thread which workers were
175 // woken up. 175 // woken up.
176 Atomics.store(i32a, id, 1); 176 Atomics.store(i32a, id, 1);
177 postMessage(result); 177 postMessage(result);
178 };`; 178 };`;
179 179
180 var id; 180 var id;
181 var workers = []; 181 var workers = [];
182 for (id = 0; id < 4; id++) { 182 for (id = 0; id < 4; id++) {
183 workers[id] = new Worker(workerScript); 183 workers[id] = new Worker(workerScript);
184 workers[id].postMessage({sab: sab, id: id}, [sab]); 184 workers[id].postMessage({sab: sab, id: id});
185 } 185 }
186 186
187 // Spin until all workers are waiting on the futex. 187 // Spin until all workers are waiting on the futex.
188 while (%AtomicsNumWaitersForTesting(i32a, 4) != 4) {} 188 while (%AtomicsNumWaitersForTesting(i32a, 4) != 4) {}
189 189
190 // Wake up three waiters. 190 // Wake up three waiters.
191 assertEquals(3, Atomics.wake(i32a, 4, 3)); 191 assertEquals(3, Atomics.wake(i32a, 4, 3));
192 192
193 var wokenCount = 0; 193 var wokenCount = 0;
194 var waitingId = 0 + 1 + 2 + 3; 194 var waitingId = 0 + 1 + 2 + 3;
(...skipping 17 matching lines...) Expand all
212 // Finally wake the last waiter. 212 // Finally wake the last waiter.
213 assertEquals(1, Atomics.wake(i32a, 4, 1)); 213 assertEquals(1, Atomics.wake(i32a, 4, 1));
214 assertEquals("ok", workers[waitingId].getMessage()); 214 assertEquals("ok", workers[waitingId].getMessage());
215 workers[waitingId].terminate(); 215 workers[waitingId].terminate();
216 216
217 assertEquals(0, %AtomicsNumWaitersForTesting(i32a, 4)); 217 assertEquals(0, %AtomicsNumWaitersForTesting(i32a, 4));
218 218
219 })(); 219 })();
220 220
221 } 221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698