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.396 by dl, Sun Feb 7 15:01:38 2021 UTC vs.
Revision 1.397 by dl, Fri Feb 12 13:20:16 2021 UTC

# Line 2113 | Line 2113 | public class ForkJoinPool extends Abstra
2113                      lock.unlock();
2114                  }
2115              }
2116 <            else if (!q.tryLock())                  // move and restart
2117 <                id = (r = ThreadLocalRandom.advanceProbe(r)) << 1;
2118 <            else
2116 >            else if (q.tryLock())
2117                  return q;
2118 +            else if ((md & SMASK) != 0)             // move unless no parallelism
2119 +                id = (r = ThreadLocalRandom.advanceProbe(r)) << 1;
2120          }
2121      }
2122  
# Line 2528 | Line 2528 | public class ForkJoinPool extends Abstra
2528                  parallelism = Integer.parseInt(pp);
2529          } catch (Exception ignore) {
2530          }
2531        int p = this.mode = Math.min(Math.max(parallelism, 0), MAX_CAP);
2532        int maxSpares = (p == 0) ? 0 : COMMON_MAX_SPARES;
2533        int bnds = ((1 - p) & SMASK) | (maxSpares << SWIDTH);
2534        int size = 1 << (33 - Integer.numberOfLeadingZeros(p > 0 ? p - 1 : 1));
2535        this.factory = (fac != null) ? fac :
2536            new DefaultCommonPoolForkJoinWorkerThreadFactory();
2531          this.ueh = handler;
2532          this.keepAlive = DEFAULT_KEEPALIVE;
2533          this.saturate = null;
2534          this.workerNamePrefix = null;
2535 <        this.bounds = bnds;
2536 <        this.ctl = ((((long)(-p) << TC_SHIFT) & TC_MASK) |
2537 <                    (((long)(-p) << RC_SHIFT) & RC_MASK));
2535 >        int p = Math.min(Math.max(parallelism, 0), MAX_CAP), size;
2536 >        if (p > 0) {
2537 >            size = 1 << (33 - Integer.numberOfLeadingZeros(p - 1));
2538 >            this.bounds = ((1 - p) & SMASK) | (COMMON_MAX_SPARES << SWIDTH);
2539 >            this.ctl = ((((long)(-p) << TC_SHIFT) & TC_MASK) |
2540 >                        (((long)(-p) << RC_SHIFT) & RC_MASK));
2541 >        } else {  // zero min, max, spare counts, 1 slot
2542 >            size = 1;
2543 >            this.bounds = 0;
2544 >            this.ctl = 0L;
2545 >        }
2546 >        this.factory = (fac != null) ? fac :
2547 >            new DefaultCommonPoolForkJoinWorkerThreadFactory();
2548          this.queues = new WorkQueue[size];
2549          this.registrationLock = new ReentrantLock();
2550      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines