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.69 by jsr166, Wed Sep 1 20:12:39 2010 UTC vs.
Revision 1.72 by jsr166, Tue Sep 7 06:19:05 2010 UTC

# Line 7 | Line 7
7   package jsr166y;
8  
9   import java.util.concurrent.*;
10
10   import java.util.ArrayList;
11   import java.util.Arrays;
12   import java.util.Collection;
# Line 301 | Line 300 | public class ForkJoinPool extends Abstra
300       * about the same time as another is needlessly being created. We
301       * counteract this and related slop in part by requiring resumed
302       * spares to immediately recheck (in preStep) to see whether they
303 <     * they should re-suspend.
303 >     * should re-suspend.
304       *
305       * 6. Killing off unneeded workers. A timeout mechanism is used to
306       * shed unused workers: The oldest (first) event queue waiter uses
# Line 430 | Line 429 | public class ForkJoinPool extends Abstra
429  
430      /**
431       * The wakeup interval (in nanoseconds) for the oldest worker
432 <     * worker waiting for an event invokes tryShutdownUnusedWorker to shrink
432 >     * waiting for an event invokes tryShutdownUnusedWorker to shrink
433       * the number of workers.  The exact value does not matter too
434       * much, but should be long enough to slowly release resources
435       * during long periods without use without disrupting normal use.
# Line 674 | Line 673 | public class ForkJoinPool extends Abstra
673      }
674  
675      /**
676 <     * Nulls out record of worker in workers array
676 >     * Nulls out record of worker in workers array.
677       */
678      private void forgetWorker(ForkJoinWorkerThread w) {
679          int idx = w.poolIndex;
# Line 1107 | Line 1106 | public class ForkJoinPool extends Abstra
1106                                       c = eventCount, c+1);
1107              eventWaiters = 0L; // clobber lists
1108              spareWaiters = 0;
1109 <            ForkJoinWorkerThread[] ws = workers;
1111 <            int n = ws.length;
1112 <            for (int i = 0; i < n; ++i) {
1113 <                ForkJoinWorkerThread w = ws[i];
1109 >            for (ForkJoinWorkerThread w : workers) {
1110                  if (w != null) {
1111                      w.shutdown();
1112                      if (passes > 0 && !w.isTerminated()) {
# Line 1129 | Line 1125 | public class ForkJoinPool extends Abstra
1125      }
1126  
1127      /**
1128 <     * Clear out and cancel submissions, ignoring exceptions
1128 >     * Clears out and cancels submissions, ignoring exceptions.
1129       */
1130      private void cancelSubmissions() {
1131          ForkJoinTask<?> task;
# Line 1144 | Line 1140 | public class ForkJoinPool extends Abstra
1140      // misc support for ForkJoinWorkerThread
1141  
1142      /**
1143 <     * Returns pool number
1143 >     * Returns pool number.
1144       */
1145      final int getPoolNumber() {
1146          return poolNumber;
1147      }
1148  
1149      /**
1150 <     * Tries to accumulates steal count from a worker, clearing
1151 <     * the worker's value.
1150 >     * Tries to accumulate steal count from a worker, clearing
1151 >     * the worker's value if successful.
1152       *
1153       * @return true if worker steal count now zero
1154       */
# Line 1176 | Line 1172 | public class ForkJoinPool extends Abstra
1172          int pc = parallelism; // use parallelism, not rc
1173          int ac = runState;    // no mask -- artificially boosts during shutdown
1174          // Use exact results for small values, saturate past 4
1175 <        return pc <= ac? 0 : pc >>> 1 <= ac? 1 : pc >>> 2 <= ac? 3 : pc >>> 3;
1175 >        return ((pc <= ac) ? 0 :
1176 >                (pc >>> 1 <= ac) ? 1 :
1177 >                (pc >>> 2 <= ac) ? 3 :
1178 >                pc >>> 3);
1179      }
1180  
1181      // Public and protected methods
# Line 1527 | Line 1526 | public class ForkJoinPool extends Abstra
1526       */
1527      public long getQueuedTaskCount() {
1528          long count = 0;
1529 <        ForkJoinWorkerThread[] ws = workers;
1531 <        int n = ws.length;
1532 <        for (int i = 0; i < n; ++i) {
1533 <            ForkJoinWorkerThread w = ws[i];
1529 >        for (ForkJoinWorkerThread w : workers)
1530              if (w != null)
1531                  count += w.getQueueSize();
1536        }
1532          return count;
1533      }
1534  
# Line 1588 | Line 1583 | public class ForkJoinPool extends Abstra
1583       */
1584      protected int drainTasksTo(Collection<? super ForkJoinTask<?>> c) {
1585          int count = submissionQueue.drainTo(c);
1586 <        ForkJoinWorkerThread[] ws = workers;
1592 <        int n = ws.length;
1593 <        for (int i = 0; i < n; ++i) {
1594 <            ForkJoinWorkerThread w = ws[i];
1586 >        for (ForkJoinWorkerThread w : workers)
1587              if (w != null)
1588                  count += w.drainTasksTo(c);
1597        }
1589          return count;
1590      }
1591  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines