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

Comparing jsr166/src/jsr166e/CountedCompleter.java (file contents):
Revision 1.5 by dl, Tue Oct 30 14:23:03 2012 UTC vs.
Revision 1.12 by jsr166, Sun Nov 18 18:03:10 2012 UTC

# Line 5 | Line 5
5   */
6  
7   package jsr166e;
8 +
9   /**
10   * A {@link ForkJoinTask} with a completion action
11   * performed when triggered and there are no remaining pending
# Line 76 | Line 77 | package jsr166e;
77   * continuations, other threads need not block waiting to perform
78   * them.
79   *
80 < * <p> For example, here is an initial version of a class that uses
80 > * <p>For example, here is an initial version of a class that uses
81   * divide-by-two recursive decomposition to divide work into single
82   * pieces (leaf tasks). Even when work is split into individual calls,
83   * tree-based techniques are usually preferable to directly forking
# Line 141 | Line 142 | package jsr166e;
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. Additionally,
145 < * this version uses {@code helpComplete} to streamline assistance in
146 < * the execution of forked tasks.
145 > * original task, and add a pending count for each fork.
146   *
147   * <pre> {@code
148   * class ForEach<E> ...
# Line 157 | Line 156 | package jsr166e;
156   *         }
157   *         if (h > l)
158   *             op.apply(array[l]);
159 < *         helpComplete();
159 > *         tryComplete();
160   *     }
161   * }</pre>
162   *
# Line 413 | Line 412 | public abstract class CountedCompleter<T
412      }
413  
414      /**
416     * Identical to {@link #tryComplete}, but may additionally execute
417     * other tasks within the current computation (i.e., those
418     * with the same {@link #getRoot}.
419     */
420    public final void helpComplete() {
421        CountedCompleter<?> a = this, s = a;
422        for (int c;;) {
423            if ((c = a.pending) == 0) {
424                a.onCompletion(s);
425                if ((a = (s = a).completer) == null) {
426                    s.quietlyComplete();
427                    return;
428                }
429            }
430            else if (U.compareAndSwapInt(a, PENDING, c, c - 1)) {
431                CountedCompleter<?> root = a.getRoot();
432                Thread thread = Thread.currentThread();
433                ForkJoinPool.WorkQueue wq =
434                    (thread instanceof ForkJoinWorkerThread)?
435                    ((ForkJoinWorkerThread)thread).workQueue : null;
436                ForkJoinTask<?> t;
437                while ((t = (wq != null) ? wq.popCC(root) :
438                        ForkJoinPool.popCCFromCommonPool(root)) != null) {
439                    t.doExec();
440                    if (root.isDone())
441                        break;
442                }
443                return;
444            }
445        }
446    }
447
448    /**
415       * Regardless of pending count, invokes {@link #onCompletion},
416       * marks this task as complete and further triggers {@link
417       * #tryComplete} on this task's completer, if one exists. This
# Line 539 | Line 505 | public abstract class CountedCompleter<T
505              }
506          }
507      }
542
508   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines