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

Comparing jsr166/src/jsr166y/CountedCompleter.java (file contents):
Revision 1.6 by dl, Tue Oct 30 14:23:11 2012 UTC vs.
Revision 1.12 by jsr166, Wed Nov 14 20:06:49 2012 UTC

# Line 142 | Line 142 | package jsr166y;
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,
146 < * this version uses {@code helpComplete} to streamline assistance in
147 < * 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 158 | Line 156 | package jsr166y;
156   *         }
157   *         if (h > l)
158   *             op.apply(array[l]);
159 < *         helpComplete();
159 > *         tryComplete();
160   *     }
161   * }</pre>
162   *
# Line 414 | Line 412 | public abstract class CountedCompleter<T
412      }
413  
414      /**
417     * Identical to {@link #tryComplete}, but may additionally execute
418     * other tasks within the current computation (i.e., those
419     * with the same {@link #getRoot}.
420     */
421    public final void helpComplete() {
422        CountedCompleter<?> a = this, s = a;
423        for (int c;;) {
424            if ((c = a.pending) == 0) {
425                a.onCompletion(s);
426                if ((a = (s = a).completer) == null) {
427                    s.quietlyComplete();
428                    return;
429                }
430            }
431            else if (U.compareAndSwapInt(a, PENDING, c, c - 1)) {
432                CountedCompleter<?> root = a.getRoot();
433                Thread thread = Thread.currentThread();
434                ForkJoinPool.WorkQueue wq =
435                    (thread instanceof ForkJoinWorkerThread)?
436                    ((ForkJoinWorkerThread)thread).workQueue : null;
437                ForkJoinTask<?> t;
438                while ((t = (wq != null) ? wq.popCC(root) :
439                        ForkJoinPool.popCCFromCommonPool(root)) != null) {
440                    t.doExec();
441                    if (root.isDone())
442                        break;
443                }
444                return;
445            }
446        }
447    }
448
449    /**
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 540 | Line 505 | public abstract class CountedCompleter<T
505              }
506          }
507      }
543
508   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines