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

Comparing jsr166/src/main/java/util/concurrent/ForkJoinPool.java (file contents):
Revision 1.285 by dl, Sun Oct 4 21:03:54 2015 UTC vs.
Revision 1.286 by dl, Mon Oct 5 15:01:30 2015 UTC

# Line 1632 | Line 1632 | public class ForkJoinPool extends Abstra
1632              w.qlock = -1;                             // ensure set
1633              w.cancelAll();                            // cancel remaining tasks
1634          }
1635 <        for (;;) {                                    // possibly replace
1635 >        while (tryTerminate(false, false) >= 0) {     // possibly replace
1636              WorkQueue[] ws; int wl, sp; long c;
1637 <            if (tryTerminate(false, false) || w == null || w.array == null ||
1637 >            if (w == null || w.array == null ||
1638                  (runState & STOP) != 0 || (ws = workQueues) == null ||
1639                  (wl = ws.length) <= 0)                // already terminating
1640                  break;
# Line 1809 | Line 1809 | public class ForkJoinPool extends Abstra
1809                           System.currentTimeMillis());
1810          if (w != null && w.scanState < 0) {
1811              int ss; AuxState aux;
1812 <            if (runState < 0 && tryTerminate(false, false))
1813 <                stat = w.qlock = -1;               // help terminate
1814 <            else if ((stat = w.qlock) >= 0 && w.scanState < 0) {
1812 >            if ((runState >= 0 ||
1813 >                 (stat = tryTerminate(false, false)) > 0) &&
1814 >                ((stat = w.qlock) >= 0 && w.scanState < 0)) {
1815                  w.parker = Thread.currentThread();
1816                  if (w.scanState < 0)
1817                      LockSupport.parkUntil(this, deadline);
# Line 2380 | Line 2380 | public class ForkJoinPool extends Abstra
2380       * @param now if true, unconditionally terminate, else only
2381       * if no work and no active workers
2382       * @param enable if true, terminate when next possible
2383 <     * @return true if now terminating or terminated
2383 >     * @return -1 : terminating or terminated, 0: retry if internal caller, else 1
2384       */
2385 <    private boolean tryTerminate(boolean now, boolean enable) {
2385 >    private int tryTerminate(boolean now, boolean enable) {
2386          AuxState aux; int rs;
2387          if ((rs = runState) >= 0 && (!enable || this == common))
2388 <            return false;
2388 >            return 1;
2389          while ((aux = auxState) == null)
2390              tryInitialize(false);
2391          aux.lock();
# Line 2397 | Line 2397 | public class ForkJoinPool extends Abstra
2397                      WorkQueue[] ws; WorkQueue w; int m, b, sp; long c;
2398                      long checkSum = ctl;
2399                      if ((int)(checkSum >> AC_SHIFT) + (config & SMASK) > 0)
2400 <                        return false;             // still active workers
2400 >                        return 0;                 // still active workers
2401                      if ((ws = workQueues) == null || (m = ws.length - 1) < 0)
2402                          break;                    // check queues
2403                    boolean clean = true;
2403                      for (int i = 0; i <= m; ++i) {
2404                          if ((w = ws[i]) != null) {
2405                              checkSum += (b = w.base);
2407                            if ((i & 1) == 0)
2408                                w.qlock = -1;     // try to disable external
2406                              if (w.currentSteal != null || b != w.top) {
2407                                  if ((sp = (int)(c = ctl)) == 0 ||
2408                                      tryRelease(c, ws[m & sp], AC_UNIT))
2409 <                                    return false; // arrange for recheck
2413 <                                clean = false;    // rescan
2409 >                                return 0;         // retry if internal caller
2410                              }
2411                          }
2412                      }
2413 <                    if (clean && oldSum == (oldSum = checkSum))
2413 >                    if (oldSum == (oldSum = checkSum))
2414                          break;
2415                  }
2416              }
# Line 2467 | Line 2463 | public class ForkJoinPool extends Abstra
2463                      tryRelease(c, ws[sp & m], AC_UNIT);
2464              }
2465          }
2466 <        return true;
2466 >        return -1;
2467      }
2468  
2469      // External operations

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines