22 |
|
* decremented; otherwise, the completion action is performed, and if |
23 |
|
* this completer itself has a completer, the process is continued |
24 |
|
* with its completer. As is the case with related synchronization |
25 |
< |
* components such as {@link Phaser} and {@link |
26 |
< |
* java.util.concurrent.Semaphore} these methods affect only internal |
27 |
< |
* counts; they do not establish any further internal bookkeeping. In |
28 |
< |
* particular, the identities of pending tasks are not maintained. As |
29 |
< |
* illustrated below, you can create subclasses that do record some or |
30 |
< |
* all pended tasks or their results when needed. |
25 |
> |
* components such as {@link java.util.concurrent.Phaser Phaser} and |
26 |
> |
* {@link java.util.concurrent.Semaphore Semaphore}, these methods |
27 |
> |
* affect only internal counts; they do not establish any further |
28 |
> |
* internal bookkeeping. In particular, the identities of pending |
29 |
> |
* tasks are not maintained. As illustrated below, you can create |
30 |
> |
* subclasses that do record some or all pending tasks or their |
31 |
> |
* results when needed. |
32 |
|
* |
33 |
|
* <p>A concrete CountedCompleter class must define method {@link |
34 |
|
* #compute}, that should, in almost all use cases, invoke {@code |
142 |
|
* |
143 |
|
* As a further improvement, notice that the left task need not even |
144 |
|
* exist. Instead of creating a new one, we can iterate using the |
145 |
< |
* original task, and add a pending count for each fork: |
145 |
> |
* original task, and add a pending count for each fork. |
146 |
|
* |
147 |
|
* <pre> {@code |
148 |
|
* class ForEach<E> ... |
378 |
|
} |
379 |
|
|
380 |
|
/** |
381 |
+ |
* Returns the root of the current computation; i.e., this |
382 |
+ |
* task if it has no completer, else its completer's root. |
383 |
+ |
* |
384 |
+ |
* @return the root of the current computation |
385 |
+ |
*/ |
386 |
+ |
public final CountedCompleter<?> getRoot() { |
387 |
+ |
CountedCompleter<?> a = this, p; |
388 |
+ |
while ((p = a.completer) != null) |
389 |
+ |
a = p; |
390 |
+ |
return a; |
391 |
+ |
} |
392 |
+ |
|
393 |
+ |
/** |
394 |
|
* If the pending count is nonzero, decrements the count; |
395 |
|
* otherwise invokes {@link #onCompletion} and then similarly |
396 |
|
* tries to complete this task's completer, if one exists, |
477 |
|
throw new Error(e); |
478 |
|
} |
479 |
|
} |
466 |
– |
|
467 |
– |
|
480 |
|
/** |
481 |
|
* Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. |
482 |
|
* Replace with a simple call to Unsafe.getUnsafe when integrating |