OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart2js.common.tasks; | 5 library dart2js.common.tasks; |
6 | 6 |
7 import 'dart:async' | 7 import 'dart:async' |
8 show Future, Zone, ZoneDelegate, ZoneSpecification, runZoned; | 8 show Future, Zone, ZoneDelegate, ZoneSpecification, runZoned; |
9 | 9 |
10 /// Used to measure where time is spent in the compiler. | 10 /// Used to measure where time is spent in the compiler. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 run: _run, runUnary: _runUnary, runBinary: _runBinary)); | 108 run: _run, runUnary: _runUnary, runBinary: _runBinary)); |
109 } | 109 } |
110 | 110 |
111 /// Run [f] in [zone]. Running must be delegated to [parent] to ensure that | 111 /// Run [f] in [zone]. Running must be delegated to [parent] to ensure that |
112 /// various state is set up correctly (in particular that `Zone.current` | 112 /// various state is set up correctly (in particular that `Zone.current` |
113 /// has the right value). Since [_measureZoned] can be called recursively | 113 /// has the right value). Since [_measureZoned] can be called recursively |
114 /// (synchronously), some of the measuring zones we create will be parents | 114 /// (synchronously), some of the measuring zones we create will be parents |
115 /// of other measuring zones, but we still need to call through the parent | 115 /// of other measuring zones, but we still need to call through the parent |
116 /// chain. Consequently, we use a zone value keyed by [measurer] to see if | 116 /// chain. Consequently, we use a zone value keyed by [measurer] to see if |
117 /// we should measure or not when delegating. | 117 /// we should measure or not when delegating. |
118 _run(Zone self, ZoneDelegate parent, Zone zone, f()) { | 118 R _run<R>(Zone self, ZoneDelegate parent, Zone zone, R f()) { |
119 if (zone[measurer] != this) return parent.run(zone, f); | 119 if (zone[measurer] != this) return parent.run(zone, f); |
120 CompilerTask previous = _start(); | 120 CompilerTask previous = _start(); |
121 try { | 121 try { |
122 return parent.run(zone, f); | 122 return parent.run(zone, f); |
123 } finally { | 123 } finally { |
124 _stop(previous); | 124 _stop(previous); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 /// Same as [run] except that [f] takes one argument, [arg]. | 128 /// Same as [run] except that [f] takes one argument, [arg]. |
129 _runUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) { | 129 R _runUnary<R, T>( |
| 130 Zone self, ZoneDelegate parent, Zone zone, R f(T arg), T arg) { |
130 if (zone[measurer] != this) return parent.runUnary(zone, f, arg); | 131 if (zone[measurer] != this) return parent.runUnary(zone, f, arg); |
131 CompilerTask previous = _start(); | 132 CompilerTask previous = _start(); |
132 try { | 133 try { |
133 return parent.runUnary(zone, f, arg); | 134 return parent.runUnary(zone, f, arg); |
134 } finally { | 135 } finally { |
135 _stop(previous); | 136 _stop(previous); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 /// Same as [run] except that [f] takes two arguments ([a1] and [a2]). | 140 /// Same as [run] except that [f] takes two arguments ([a1] and [a2]). |
140 _runBinary(Zone self, ZoneDelegate parent, Zone zone, f(a1, a2), a1, a2) { | 141 R _runBinary<R, T1, T2>(Zone self, ZoneDelegate parent, Zone zone, |
| 142 R f(T1 a1, T2 a2), T1 a1, T2 a2) { |
141 if (zone[measurer] != this) return parent.runBinary(zone, f, a1, a2); | 143 if (zone[measurer] != this) return parent.runBinary(zone, f, a1, a2); |
142 CompilerTask previous = _start(); | 144 CompilerTask previous = _start(); |
143 try { | 145 try { |
144 return parent.runBinary(zone, f, a1, a2); | 146 return parent.runBinary(zone, f, a1, a2); |
145 } finally { | 147 } finally { |
146 _stop(previous); | 148 _stop(previous); |
147 } | 149 } |
148 } | 150 } |
149 | 151 |
150 /// Asynchronous version of [measure]. Use this when action returns a future | 152 /// Asynchronous version of [measure]. Use this when action returns a future |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 242 } |
241 | 243 |
242 /// Call this when the eventloop returns control to us. | 244 /// Call this when the eventloop returns control to us. |
243 void stopAsyncWallClock() { | 245 void stopAsyncWallClock() { |
244 if (currentAsyncTask != null) { | 246 if (currentAsyncTask != null) { |
245 currentAsyncTask._watch.stop(); | 247 currentAsyncTask._watch.stop(); |
246 } | 248 } |
247 asyncWallClock.stop(); | 249 asyncWallClock.stop(); |
248 } | 250 } |
249 } | 251 } |
OLD | NEW |