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

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.79 by jsr166, Tue Sep 7 23:49:30 2010 UTC vs.
Revision 1.80 by dl, Fri Sep 17 14:24:56 2010 UTC

# Line 13 | Line 13 | import java.util.Collections;
13   import java.util.List;
14   import java.util.concurrent.AbstractExecutorService;
15   import java.util.concurrent.Callable;
16 import java.util.concurrent.CountDownLatch;
16   import java.util.concurrent.ExecutorService;
17   import java.util.concurrent.Future;
18   import java.util.concurrent.RejectedExecutionException;
# Line 794 | Line 793 | public class ForkJoinPool extends Abstra
793                                     (workerCounts & RUNNING_COUNT_MASK) <= 1);
794                  long startTime = untimed? 0 : System.nanoTime();
795                  Thread.interrupted();         // clear/ignore interrupt
796 <                if (eventCount != ec || w.runState != 0 ||
797 <                    runState >= TERMINATING)  // recheck after clear
799 <                    break;
796 >                if (eventCount != ec || w.isTerminating())
797 >                    break;                    // recheck after clear
798                  if (untimed)
799                      LockSupport.park(w);
800                  else {
801                      LockSupport.parkNanos(w, SHRINK_RATE_NANOS);
802 <                    if (eventCount != ec || w.runState != 0 ||
805 <                        runState >= TERMINATING)
802 >                    if (eventCount != ec || w.isTerminating())
803                          break;
804                      if (System.nanoTime() - startTime >= SHRINK_RATE_NANOS)
805                          tryShutdownUnusedWorker(ec);
# Line 870 | Line 867 | public class ForkJoinPool extends Abstra
867                       UNSAFE.compareAndSwapInt(this, workerCountsOffset, wc,
868                                                wc + (ONE_RUNNING|ONE_TOTAL))) {
869                  ForkJoinWorkerThread w = null;
870 +                Throwable fail = null;
871                  try {
872                      w = factory.newThread(this);
873 <                } finally { // adjust on null or exceptional factory return
874 <                    if (w == null) {
877 <                        decrementWorkerCounts(ONE_RUNNING, ONE_TOTAL);
878 <                        tryTerminate(false); // handle failure during shutdown
879 <                    }
873 >                } catch (Throwable ex) {
874 >                    fail = ex;
875                  }
876 <                if (w == null)
876 >                if (w == null) { // null or exceptional factory return
877 >                    decrementWorkerCounts(ONE_RUNNING, ONE_TOTAL);
878 >                    tryTerminate(false); // handle failure during shutdown
879 >                    // If originating from an external caller,
880 >                    // propagate exception, else ignore
881 >                    if (fail != null && runState < TERMINATING &&
882 >                        !(Thread.currentThread() instanceof
883 >                          ForkJoinWorkerThread))
884 >                        UNSAFE.throwException(fail);
885                      break;
886 +                }
887                  w.start(recordWorker(w), ueh);
888                  if ((workerCounts >>> TOTAL_COUNT_SHIFT) >= pc) {
889                      int c; // advance event count
# Line 968 | Line 972 | public class ForkJoinPool extends Abstra
972          boolean active = w.active;
973          boolean inactivate = false;
974          int pc = parallelism;
975 <        int rs;
976 <        while (w.runState == 0 && (rs = runState) < TERMINATING) {
975 >        while (w.runState == 0) {
976 >            int rs = runState;
977 >            if (rs >= TERMINATING) { // propagate shutdown
978 >                w.shutdown();
979 >                break;
980 >            }
981              if ((inactivate || (active && (rs & ACTIVE_COUNT_MASK) >= pc)) &&
982                  UNSAFE.compareAndSwapInt(this, runStateOffset, rs, rs - 1))
983                  inactivate = active = w.active = false;
# Line 1097 | Line 1105 | public class ForkJoinPool extends Abstra
1105          return true;
1106      }
1107  
1108 +
1109      /**
1110       * Actions on transition to TERMINATING
1111       *
# Line 1120 | Line 1129 | public class ForkJoinPool extends Abstra
1129                      if (passes > 0 && !w.isTerminated()) {
1130                          w.cancelTasks();
1131                          LockSupport.unpark(w);
1132 <                        if (passes > 1) {
1132 >                        if (passes > 1 && !w.isInterrupted()) {
1133                              try {
1134                                  w.interrupt();
1135                              } catch (SecurityException ignore) {
# Line 1697 | Line 1706 | public class ForkJoinPool extends Abstra
1706      }
1707  
1708      /**
1709 +     * Returns true if terminating or terminated. Used by ForkJoinWorkerThread.
1710 +     */
1711 +    final boolean isAtLeastTerminating() {
1712 +        return runState >= TERMINATING;
1713 +    }
1714 +        
1715 +    /**
1716       * Returns {@code true} if this pool has been shut down.
1717       *
1718       * @return {@code true} if this pool has been shut down

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines