13 |
|
* have smaller stack space footprints and faster completion mechanics |
14 |
|
* but higher per-task footprints. Compared to LinkedAsyncActions, |
15 |
|
* BinaryAsyncActions are simpler to use and have less overhead in |
16 |
< |
* typical uasges but are restricted to binary computation trees. |
16 |
> |
* typical usages but are restricted to binary computation trees. |
17 |
|
* |
18 |
|
* <p>Upon construction, a BinaryAsyncAction does not bear any |
19 |
|
* linkages. For non-root tasks, links must be established using |
38 |
|
* } |
39 |
|
* } |
40 |
|
* </pre> |
41 |
< |
* An alternative, and usually faster strategy is to instead use a |
41 |
> |
* An alternative, and usually faster, strategy is to instead use a |
42 |
|
* loop to fork subtasks: |
43 |
|
* <pre> |
44 |
|
* protected void compute() { |
57 |
|
* </pre> |
58 |
|
*/ |
59 |
|
public abstract class BinaryAsyncAction extends ForkJoinTask<Void> { |
60 |
– |
private volatile int controlState; |
61 |
– |
|
62 |
– |
static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater = |
63 |
– |
AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class, "controlState"); |
60 |
|
|
61 |
|
/** |
62 |
|
* Parent to propagate completion; nulled after completion to |
85 |
|
* as parent, and each other as siblings. |
86 |
|
* @param x one subtask |
87 |
|
* @param y the other subtask |
88 |
< |
* @throws NullPointerException if either argument is null. |
88 |
> |
* @throws NullPointerException if either argument is null |
89 |
|
*/ |
90 |
|
public final void linkSubtasks(BinaryAsyncAction x, BinaryAsyncAction y) { |
91 |
|
x.parent = y.parent = this; |
116 |
|
* default version of this method does nothing and returns |
117 |
|
* {@code true}. |
118 |
|
* @return true if this task's exception should be propagated to |
119 |
< |
* this task's parent. |
119 |
> |
* this task's parent |
120 |
|
*/ |
121 |
|
protected boolean onException() { |
122 |
|
return true; |
165 |
|
a.sibling = null; |
166 |
|
a.parent = null; |
167 |
|
a.completeThis(); |
168 |
< |
if (p == null || p.compareAndSetControlState(0, 1)) |
168 |
> |
if (p == null || p.markForkJoinTask()) |
169 |
|
break; |
170 |
|
try { |
171 |
|
p.onComplete(a, s); |
188 |
|
* @param ex the exception to throw when joining this task |
189 |
|
* @throws NullPointerException if ex is null |
190 |
|
* @throws Throwable if any invocation of |
191 |
< |
* {@code onException} does so. |
191 |
> |
* {@code onException} does so |
192 |
|
*/ |
193 |
|
public final void completeExceptionally(Throwable ex) { |
194 |
|
BinaryAsyncAction a = this; |
205 |
|
/** |
206 |
|
* Returns this task's parent, or null if none or this task |
207 |
|
* is already complete. |
208 |
< |
* @return this task's parent, or null if none. |
208 |
> |
* @return this task's parent, or null if none |
209 |
|
*/ |
210 |
|
public final BinaryAsyncAction getParent() { |
211 |
|
return parent; |
214 |
|
/** |
215 |
|
* Returns this task's sibling, or null if none or this task is |
216 |
|
* already complete. |
217 |
< |
* @return this task's sibling, or null if none. |
217 |
> |
* @return this task's sibling, or null if none |
218 |
|
*/ |
219 |
|
public BinaryAsyncAction getSibling() { |
220 |
|
return sibling; |
229 |
|
super.reinitialize(); |
230 |
|
} |
231 |
|
|
232 |
+ |
<<<<<<< BinaryAsyncAction.java |
233 |
+ |
======= |
234 |
|
/** |
235 |
|
* Gets the control state, which is initially zero, or negative if |
236 |
|
* this task has completed or cancelled. Once negative, the value |
265 |
|
} |
266 |
|
|
267 |
|
/** |
268 |
< |
* Sets the control state to the given value, |
268 |
> |
* Increments the control state. |
269 |
|
* @param value the new value |
270 |
|
*/ |
271 |
|
protected final void incrementControlState() { |
273 |
|
} |
274 |
|
|
275 |
|
/** |
276 |
< |
* Decrement the control state |
276 |
> |
* Decrements the control state. |
277 |
|
* @return true if successful |
278 |
|
*/ |
279 |
|
protected final void decrementControlState() { |
280 |
|
controlStateUpdater.decrementAndGet(this); |
281 |
|
} |
282 |
+ |
>>>>>>> 1.14 |
283 |
|
|
284 |
|
} |