OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 $.agent = (function () { | 5 $262.agent = (function () { |
6 | 6 |
7 var workers = []; | 7 var workers = []; |
8 var i32a = null; | 8 var i32a = null; |
9 var pendingReports = []; | 9 var pendingReports = []; |
10 | 10 |
11 // Agents call Atomics.wait on this location to sleep. | 11 // Agents call Atomics.wait on this location to sleep. |
12 var SLEEP_LOC = 0; | 12 var SLEEP_LOC = 0; |
13 // 1 if the started worker is ready, 0 otherwise. | 13 // 1 if the started worker is ready, 0 otherwise. |
14 var START_LOC = 1; | 14 var START_LOC = 1; |
15 // The number of workers that have received the broadcast. | 15 // The number of workers that have received the broadcast. |
(...skipping 25 matching lines...) Expand all Loading... |
41 break; | 41 break; |
42 | 42 |
43 case 'broadcast': | 43 case 'broadcast': |
44 Atomics.add(i32a, ${BROADCAST_LOC}, 1); | 44 Atomics.add(i32a, ${BROADCAST_LOC}, 1); |
45 broadcasts.push([msg.sab, msg.id]); | 45 broadcasts.push([msg.sab, msg.id]); |
46 handleBroadcast(); | 46 handleBroadcast(); |
47 break; | 47 break; |
48 } | 48 } |
49 }; | 49 }; |
50 | 50 |
51 var $ = { | 51 var $262 = { |
52 agent: { | 52 agent: { |
53 receiveBroadcast(receiver) { | 53 receiveBroadcast(receiver) { |
54 pendingReceiver = receiver; | 54 pendingReceiver = receiver; |
55 handleBroadcast(); | 55 handleBroadcast(); |
56 }, | 56 }, |
57 | 57 |
58 report(msg) { | 58 report(msg) { |
59 postMessage(msg); | 59 postMessage(msg); |
60 Atomics.add(i32a, ${WORKER_REPORT_LOC} + index, 1); | 60 Atomics.add(i32a, ${WORKER_REPORT_LOC} + index, 1); |
61 }, | 61 }, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 return pendingReports.shift() || null; | 99 return pendingReports.shift() || null; |
100 }, | 100 }, |
101 | 101 |
102 sleep(s) { Atomics.wait(i32a, SLEEP_LOC, 0, s); } | 102 sleep(s) { Atomics.wait(i32a, SLEEP_LOC, 0, s); } |
103 }; | 103 }; |
104 return agent; | 104 return agent; |
105 | 105 |
106 })(); | 106 })(); |
OLD | NEW |