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); |
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 (;;) { |
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 |
|
} |
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); |
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 |
|
} |
1406 |
|
} |
1407 |
|
|
1408 |
|
public boolean isShutdown() { |
1409 |
< |
return ! isRunning(ctl.get()); |
1409 |
> |
return runStateAtLeast(ctl.get(), SHUTDOWN); |
1410 |
|
} |
1411 |
|
|
1412 |
|
/** Used by ScheduledThreadPoolExecutor. */ |
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() { |
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); |
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() + |