ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/LinkedAsyncAction.java
(Generate patch)

Comparing jsr166/src/test/loops/LinkedAsyncAction.java (file contents):
Revision 1.1 by dl, Sun Sep 19 12:55:37 2010 UTC vs.
Revision 1.7 by jsr166, Sun Nov 25 21:37:28 2012 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < *
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import java.util.*;
# Line 11 | Line 11 | import java.util.concurrent.atomic.*;
11   /**
12   * AsyncActions that may be linked in parent-child relationships.
13   *
14 < * <p> Upon construction, an LinkedAsyncAction may register as a
14 > * <p>Upon construction, an LinkedAsyncAction may register as a
15   * subtask of a given parent task. In this case, completion of this
16   * task will propagate to its parent. If the parent's pending subtask
17   * completion count becomes zero, it too will complete.
# Line 24 | Line 24 | import java.util.concurrent.atomic.*;
24   * <tt>complete</tt> of the subtask will trigger <tt>complete</tt> of the
25   * parent without the parent explicitly doing so.
26   *
27 < * <p> In addition to supporting these different computation styles
27 > * <p>In addition to supporting these different computation styles
28   * compared to Recursive tasks, LinkedAsyncActions may have smaller
29   * stack space footprints while executing, but may have greater
30   * per-task overhead.
31   *
32 < * <p> <b>Sample Usage.</b> Here is a sketch of an LinkedAsyncAction
32 > * <p><b>Sample Usage.</b> Here is a sketch of an LinkedAsyncAction
33   * that visits all of the nodes of a graph. The details of the graph's
34   * Node and Edge classes are omitted, but we assume each node contains
35   * an <tt>AtomicBoolean</tt> mark that starts out false. To execute
# Line 39 | Line 39 | import java.util.concurrent.atomic.*;
39   *
40   * <pre>
41   * class GraphVisitor extends LinkedAsyncAction {
42 < *    final Node node;
43 < *    GraphVisitor(GraphVistor parent, Node node) {
44 < *      super(parent); this.node = node;
45 < *    }
46 < *    protected void compute() {
47 < *      if (node.mark.compareAndSet(false, true)) {
48 < *         for (Edge e : node.edges()) {
49 < *            Node dest = e.getDestination();
50 < *            if (!dest.mark.get())
51 < *               new GraphVisitor(this, dest).fork();
52 < *         }
53 < *         visit(node);
54 < *      }
55 < *      complete();
42 > *   final Node node;
43 > *   GraphVisitor(GraphVistor parent, Node node) {
44 > *     super(parent); this.node = node;
45 > *   }
46 > *   protected void compute() {
47 > *     if (node.mark.compareAndSet(false, true)) {
48 > *       for (Edge e : node.edges()) {
49 > *         Node dest = e.getDestination();
50 > *         if (!dest.mark.get())
51 > *           new GraphVisitor(this, dest).fork();
52 > *       }
53 > *       visit(node);
54 > *     }
55 > *     complete();
56   *   }
57   * }
58   * </pre>
59 *
59   */
60   public abstract class LinkedAsyncAction extends ForkJoinTask<Void> {
61  
# Line 141 | Line 140 | public abstract class LinkedAsyncAction
140       * Overridable callback action triggered by <tt>complete</tt>.  Upon
141       * invocation, all subtasks have completed.  After return, this
142       * task <tt>isDone</tt> and is joinable by other tasks. The
143 <     * default version of this method does nothing. But it may may be
143 >     * default version of this method does nothing. But it may be
144       * overridden in subclasses to perform some action when this task
145       * is about to complete.
146       */
# Line 312 | Line 311 | public abstract class LinkedAsyncAction
311       * @param update the new value
312       * @return true if successful
313       */
314 <    protected final boolean compareAndSetControlState(int expect,
314 >    protected final boolean compareAndSetControlState(int expect,
315                                                        int update) {
316          return controlStateUpdater.compareAndSet(this, expect, update);
317      }
318  
319      /**
320 <     * Sets the control state to the given value,
320 >     * Sets the control state to the given value.
321       * @param value the new value
322       */
323      protected final void setControlState(int value) {
# Line 326 | Line 325 | public abstract class LinkedAsyncAction
325      }
326  
327      /**
328 <     * Increment the control state
328 >     * Increments the control state.
329       * @return true if successful
330       */
331      protected final void incrementControlState() {
# Line 334 | Line 333 | public abstract class LinkedAsyncAction
333      }
334  
335      /**
336 <     * Decrement the control state
336 >     * Decrements the control state.
337       * @return true if successful
338       */
339      protected final void decrementControlState() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines