ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ForkJoinTask.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ForkJoinTask.java (file contents):
Revision 1.74 by jsr166, Mon Feb 11 07:46:34 2013 UTC vs.
Revision 1.75 by dl, Sun May 5 19:25:01 2013 UTC

# Line 285 | Line 285 | public abstract class ForkJoinTask<V> im
285       */
286      private int externalAwaitDone() {
287          int s;
288 <        ForkJoinPool.externalHelpJoin(this);
289 <        boolean interrupted = false;
290 <        while ((s = status) >= 0) {
291 <            if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
292 <                synchronized (this) {
293 <                    if (status >= 0) {
294 <                        try {
295 <                            wait();
296 <                        } catch (InterruptedException ie) {
297 <                            interrupted = true;
288 >        ForkJoinPool cp = ForkJoinPool.common;
289 >        if ((s = status) >= 0) {
290 >            if (cp != null) {
291 >                if (this instanceof CountedCompleter)
292 >                    s = cp.externalHelpComplete((CountedCompleter<?>)this);
293 >                else if (cp.tryExternalUnpush(this))
294 >                    s = doExec();
295 >            }
296 >            if (s >= 0 && (s = status) >= 0) {
297 >                boolean interrupted = false;
298 >                do {
299 >                    if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
300 >                        synchronized (this) {
301 >                            if (status >= 0) {
302 >                                try {
303 >                                    wait();
304 >                                } catch (InterruptedException ie) {
305 >                                    interrupted = true;
306 >                                }
307 >                            }
308 >                            else
309 >                                notifyAll();
310                          }
311                      }
312 <                    else
313 <                        notifyAll();
314 <                }
312 >                } while ((s = status) >= 0);
313 >                if (interrupted)
314 >                    Thread.currentThread().interrupt();
315              }
316          }
305        if (interrupted)
306            Thread.currentThread().interrupt();
317          return s;
318      }
319  
# Line 312 | Line 322 | public abstract class ForkJoinTask<V> im
322       */
323      private int externalInterruptibleAwaitDone() throws InterruptedException {
324          int s;
325 +        ForkJoinPool cp = ForkJoinPool.common;
326          if (Thread.interrupted())
327              throw new InterruptedException();
328 <        ForkJoinPool.externalHelpJoin(this);
328 >        if ((s = status) >= 0 && cp != null) {
329 >            if (this instanceof CountedCompleter)
330 >                cp.externalHelpComplete((CountedCompleter<?>)this);
331 >            else if (cp.tryExternalUnpush(this))
332 >                doExec();
333 >        }
334          while ((s = status) >= 0) {
335              if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
336                  synchronized (this) {
# Line 981 | Line 997 | public abstract class ForkJoinTask<V> im
997          // Messy in part because we measure in nanosecs, but wait in millisecs
998          int s; long ms;
999          long ns = unit.toNanos(timeout);
1000 +        ForkJoinPool cp;
1001          if ((s = status) >= 0 && ns > 0L) {
1002              long deadline = System.nanoTime() + ns;
1003              ForkJoinPool p = null;
# Line 992 | Line 1009 | public abstract class ForkJoinTask<V> im
1009                  w = wt.workQueue;
1010                  p.helpJoinOnce(w, this); // no retries on failure
1011              }
1012 <            else
1013 <                ForkJoinPool.externalHelpJoin(this);
1012 >            else if ((cp = ForkJoinPool.common) != null) {
1013 >                if (this instanceof CountedCompleter)
1014 >                    cp.externalHelpComplete((CountedCompleter<?>)this);
1015 >                else if (cp.tryExternalUnpush(this))
1016 >                    doExec();
1017 >            }
1018              boolean canBlock = false;
1019              boolean interrupted = false;
1020              try {
# Line 1001 | Line 1022 | public abstract class ForkJoinTask<V> im
1022                      if (w != null && w.qlock < 0)
1023                          cancelIgnoringExceptions(this);
1024                      else if (!canBlock) {
1025 <                        if (p == null || p.tryCompensate())
1025 >                        if (p == null || p.tryCompensate(p.ctl))
1026                              canBlock = true;
1027                      }
1028                      else {
# Line 1142 | Line 1163 | public abstract class ForkJoinTask<V> im
1163          Thread t;
1164          return (((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ?
1165                  ((ForkJoinWorkerThread)t).workQueue.tryUnpush(this) :
1166 <                ForkJoinPool.tryExternalUnpush(this));
1166 >                ForkJoinPool.common.tryExternalUnpush(this));
1167      }
1168  
1169      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines