--- jsr166/src/test/loops/BinaryAsyncAction.java 2012/01/28 04:40:12 1.4
+++ jsr166/src/test/loops/BinaryAsyncAction.java 2015/09/12 18:11:24 1.17
@@ -1,7 +1,7 @@
/*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
- *
+ * http://creativecommons.org/publicdomain/zero/1.0/
*/
import java.util.concurrent.*;
@@ -13,13 +13,13 @@ import java.util.concurrent.atomic.*;
* have smaller stack space footprints and faster completion mechanics
* but higher per-task footprints. Compared to LinkedAsyncActions,
* BinaryAsyncActions are simpler to use and have less overhead in
- * typical uasges but are restricted to binary computation trees.
+ * typical usages but are restricted to binary computation trees.
*
- *
Upon construction, an BinaryAsyncAction does not bear any
+ *
Upon construction, a BinaryAsyncAction does not bear any
* linkages. For non-root tasks, links must be established using
- * method linkSubtasks before use.
+ * method {@link #linkSubtasks} before use.
*
- *
Sample Usage. A version of Fibonacci:
+ *
Sample Usage. A version of Fibonacci:
*
* class Fib extends BinaryAsyncAction {
* final int n;
@@ -27,28 +27,28 @@ import java.util.concurrent.atomic.*;
* Fib(int n) { this.n = n; }
* protected void compute() {
* if (n > 1) {
- * linkAndForkSubtasks(new Fib(n-1), new Fib(n-2));
+ * linkAndForkSubtasks(new Fib(n-1), new Fib(n-2));
* else {
- * result = n; // fib(0)==0; fib(1)==1
- * complete();
+ * result = n; // fib(0)==0; fib(1)==1
+ * complete();
* }
* }
* protected void onComplete(BinaryAsyncAction x, BinaryAsyncAction y) {
- * result = ((Fib)x).result + ((Fib)y).result;
+ * result = ((Fib)x).result + ((Fib)y).result;
* }
* }
*
- * An alternative, and usually faster strategy is to instead use a
+ * An alternative, and usually faster, strategy is to instead use a
* loop to fork subtasks:
*
* protected void compute() {
* Fib f = this;
* while (f.n > 1) {
- * Fib left = new Fib(f.n - 1);
- * Fib right = new Fib(f.n - 2);
- * f.linkSubtasks(left, right);
- * right.fork(); // fork right
- * f = left; // loop on left
+ * Fib left = new Fib(f.n - 1);
+ * Fib right = new Fib(f.n - 2);
+ * f.linkSubtasks(left, right);
+ * right.fork(); // fork right
+ * f = left; // loop on left
* }
* f.result = f.n;
* f.complete();
@@ -57,10 +57,6 @@ import java.util.concurrent.atomic.*;
*
*/
public abstract class BinaryAsyncAction extends ForkJoinTask {
- private volatile int controlState;
-
- static final AtomicIntegerFieldUpdater controlStateUpdater =
- AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class, "controlState");
/**
* Parent to propagate completion; nulled after completion to
@@ -75,7 +71,7 @@ public abstract class BinaryAsyncAction
/**
* Creates a new action. Unless this is a root task, you will need
- * to link it using method linkSubtasks before forking as
+ * to link it using method {@link #linkSubtasks} before forking as
* a subtask.
*/
protected BinaryAsyncAction() {
@@ -89,7 +85,7 @@ public abstract class BinaryAsyncAction
* as parent, and each other as siblings.
* @param x one subtask
* @param y the other subtask
- * @throws NullPointerException if either argument is null.
+ * @throws NullPointerException if either argument is null
*/
public final void linkSubtasks(BinaryAsyncAction x, BinaryAsyncAction y) {
x.parent = y.parent = this;
@@ -98,13 +94,12 @@ public abstract class BinaryAsyncAction
}
/**
- * Overridable callback action triggered upon complete of
+ * Overridable callback action triggered upon {@code complete} of
* subtasks. Upon invocation, both subtasks have completed.
- * After return, this task isDone and is joinable by
- * other tasks. The default version of this method does
- * nothing. But it may be overridden in subclasses to perform
- * some action (for example a reduction) when this task is
- * completes.
+ * After return, this task {@code isDone} and is joinable by
+ * other tasks. The default version of this method does nothing.
+ * But it may be overridden in subclasses to perform some action
+ * (for example a reduction) when this task is completes.
* @param x one subtask
* @param y the other subtask
*/
@@ -113,22 +108,22 @@ public abstract class BinaryAsyncAction
/**
* Overridable callback action triggered by
- * completeExceptionally. Upon invocation, this task has
+ * {@code completeExceptionally}. Upon invocation, this task has
* aborted due to an exception (accessible via
- * getException). If this method returns true,
+ * {@code getException}). If this method returns {@code true},
* the exception propagates to the current task's
* parent. Otherwise, normal completion is propagated. The
* default version of this method does nothing and returns
- * true.
+ * {@code true}.
* @return true if this task's exception should be propagated to
- * this tasks parent.
+ * this task's parent
*/
protected boolean onException() {
return true;
}
/**
- * Equivalent in effect to invoking linkSubtasks and then
+ * Equivalent in effect to invoking {@link #linkSubtasks} and then
* forking both tasks.
* @param x one subtask
* @param y the other subtask
@@ -157,9 +152,9 @@ public abstract class BinaryAsyncAction
/**
* Completes this task, and if this task has a sibling that is
- * also complete, invokes onComplete of parent task, and so
+ * also complete, invokes {@code onComplete} of parent task, and so
* on. If an exception is encountered, tasks instead
- * completeExceptionally.
+ * {@code completeExceptionally}.
*/
public final void complete() {
// todo: Use tryUnfork without possibly blowing stack
@@ -170,7 +165,7 @@ public abstract class BinaryAsyncAction
a.sibling = null;
a.parent = null;
a.completeThis();
- if (p == null || p.compareAndSetControlState(0, 1))
+ if (p == null || p.markForkJoinTask())
break;
try {
p.onComplete(a, s);
@@ -185,15 +180,15 @@ public abstract class BinaryAsyncAction
/**
* Completes this task abnormally. Unless this task already
* cancelled or aborted, upon invocation, this method invokes
- * onException, and then, depending on its return value,
- * completees parent (if one exists) exceptionally or normally. To
+ * {@code onException}, and then, depending on its return value,
+ * completes parent (if one exists) exceptionally or normally. To
* avoid unbounded exception loops, this method aborts if an
- * exception is encountered in any onException
+ * exception is encountered in any {@code onException}
* invocation.
* @param ex the exception to throw when joining this task
* @throws NullPointerException if ex is null
* @throws Throwable if any invocation of
- * onException does so.
+ * {@code onException} does so
*/
public final void completeExceptionally(Throwable ex) {
BinaryAsyncAction a = this;
@@ -210,7 +205,7 @@ public abstract class BinaryAsyncAction
/**
* Returns this task's parent, or null if none or this task
* is already complete.
- * @return this task's parent, or null if none.
+ * @return this task's parent, or null if none
*/
public final BinaryAsyncAction getParent() {
return parent;
@@ -219,7 +214,7 @@ public abstract class BinaryAsyncAction
/**
* Returns this task's sibling, or null if none or this task is
* already complete.
- * @return this task's sibling, or null if none.
+ * @return this task's sibling, or null if none
*/
public BinaryAsyncAction getSibling() {
return sibling;
@@ -234,6 +229,8 @@ public abstract class BinaryAsyncAction
super.reinitialize();
}
+<<<<<<< BinaryAsyncAction.java
+=======
/**
* Gets the control state, which is initially zero, or negative if
* this task has completed or cancelled. Once negative, the value
@@ -268,7 +265,7 @@ public abstract class BinaryAsyncAction
}
/**
- * Sets the control state to the given value,
+ * Increments the control state.
* @param value the new value
*/
protected final void incrementControlState() {
@@ -276,11 +273,12 @@ public abstract class BinaryAsyncAction
}
/**
- * Decrement the control state
+ * Decrements the control state.
* @return true if successful
*/
protected final void decrementControlState() {
controlStateUpdater.decrementAndGet(this);
}
+>>>>>>> 1.14
}