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

Comparing jsr166/src/main/java/util/concurrent/ThreadPoolExecutor.java (file contents):
Revision 1.177 by jsr166, Tue Sep 5 22:08:48 2017 UTC vs.
Revision 1.178 by jsr166, Fri Sep 8 02:42:22 2017 UTC

# Line 676 | Line 676 | public class ThreadPoolExecutor extends
676              int c = ctl.get();
677              if (isRunning(c) ||
678                  runStateAtLeast(c, TIDYING) ||
679 <                (runStateOf(c) == SHUTDOWN && ! workQueue.isEmpty()))
679 >                (runStateLessThan(c, STOP) && ! workQueue.isEmpty()))
680                  return;
681              if (workerCountOf(c) != 0) { // Eligible to terminate
682                  interruptIdleWorkers(ONLY_ONE);
# Line 867 | Line 867 | public class ThreadPoolExecutor extends
867       */
868      private boolean addWorker(Runnable firstTask, boolean core) {
869          retry:
870 <        for (;;) {
871 <            int c = ctl.get();
872 <            int rs = runStateOf(c);
873 <
870 >        for (int c = ctl.get();;) {
871              // Check if queue empty only if necessary.
872 <            if (rs >= SHUTDOWN &&
873 <                ! (rs == SHUTDOWN &&
874 <                   firstTask == null &&
875 <                   ! workQueue.isEmpty()))
872 >            if (runStateAtLeast(c, SHUTDOWN)
873 >                && (runStateAtLeast(c, STOP)
874 >                    || firstTask != null
875 >                    || workQueue.isEmpty()))
876                  return false;
877  
878              for (;;) {
# Line 886 | Line 883 | public class ThreadPoolExecutor extends
883                  if (compareAndIncrementWorkerCount(c))
884                      break retry;
885                  c = ctl.get();  // Re-read ctl
886 <                if (runStateOf(c) != rs)
886 >                if (runStateAtLeast(c, SHUTDOWN))
887                      continue retry;
888                  // else CAS failed due to workerCount change; retry inner loop
889              }
# Line 905 | Line 902 | public class ThreadPoolExecutor extends
902                      // Recheck while holding lock.
903                      // Back out on ThreadFactory failure or if
904                      // shut down before lock acquired.
905 <                    int rs = runStateOf(ctl.get());
905 >                    int c = ctl.get();
906  
907 <                    if (rs < SHUTDOWN ||
908 <                        (rs == SHUTDOWN && firstTask == null)) {
907 >                    if (isRunning(c) ||
908 >                        (runStateLessThan(c, STOP) && firstTask == null)) {
909                          if (t.isAlive()) // precheck that t is startable
910                              throw new IllegalThreadStateException();
911                          workers.add(w);
# Line 1015 | Line 1012 | public class ThreadPoolExecutor extends
1012  
1013          for (;;) {
1014              int c = ctl.get();
1018            int rs = runStateOf(c);
1015  
1016              // Check if queue empty only if necessary.
1017 <            if (rs >= SHUTDOWN && (rs >= STOP || workQueue.isEmpty())) {
1017 >            if (runStateAtLeast(c, SHUTDOWN)
1018 >                && (runStateAtLeast(c, STOP) || workQueue.isEmpty())) {
1019                  decrementWorkerCount();
1020                  return null;
1021              }
# Line 1409 | Line 1406 | public class ThreadPoolExecutor extends
1406      }
1407  
1408      public boolean isShutdown() {
1409 <        return ! isRunning(ctl.get());
1409 >        return runStateAtLeast(ctl.get(), SHUTDOWN);
1410      }
1411  
1412      /** Used by ScheduledThreadPoolExecutor. */
# Line 1430 | Line 1427 | public class ThreadPoolExecutor extends
1427       */
1428      public boolean isTerminating() {
1429          int c = ctl.get();
1430 <        return ! isRunning(c) && runStateLessThan(c, TERMINATED);
1430 >        return runStateAtLeast(c, SHUTDOWN) && runStateLessThan(c, TERMINATED);
1431      }
1432  
1433      public boolean isTerminated() {
# Line 1443 | Line 1440 | public class ThreadPoolExecutor extends
1440          final ReentrantLock mainLock = this.mainLock;
1441          mainLock.lock();
1442          try {
1443 <            while (!runStateAtLeast(ctl.get(), TERMINATED)) {
1443 >            while (runStateLessThan(ctl.get(), TERMINATED)) {
1444                  if (nanos <= 0L)
1445                      return false;
1446                  nanos = termination.awaitNanos(nanos);
# Line 1922 | Line 1919 | public class ThreadPoolExecutor extends
1919          }
1920          int c = ctl.get();
1921          String runState =
1922 <            runStateLessThan(c, SHUTDOWN) ? "Running" :
1922 >            isRunning(c) ? "Running" :
1923              runStateAtLeast(c, TERMINATED) ? "Terminated" :
1924              "Shutting down";
1925          return super.toString() +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines