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

Comparing jsr166/src/main/java/util/concurrent/Exchanger.java (file contents):
Revision 1.34 by dl, Mon Dec 12 20:05:48 2005 UTC vs.
Revision 1.35 by jsr166, Mon Dec 12 21:41:49 2005 UTC

# Line 121 | Line 121 | public class Exchanger<V> {
121       * out to become unstuck.  Note that the arena array holds SIZE+1
122       * elements, to include the top-of-stack slot.  Imposing a ceiling
123       * is suboptimal for huge machines, but bounds backoff times to
124 <     * acceptable values. To ensure max times less than 2.4seconds,
124 >     * acceptable values. To ensure max times less than 2.4 seconds,
125       * the ceiling value plus the shift value of backoff base (below)
126       * should be less than or equal to 31.
127       */
128      private static final int SIZE = Math.min(25, (NCPUS + 1) / 2);
129  
130      /**
131 <     * Base unit in nanoseconds for backoffs. Must be a power of two.
132 <     * Should be small because backoffs exponentially increase from
133 <     * base. The value should be close to the round-trip time of a
134 <     * call to LockSupport.park in the case where some other thread
135 <     * has already called unpark. On multiprocessors, timed waits less
136 <     * than this value are implemented by spinning.
131 >     * Base unit in nanoseconds for backoffs.  Must be a power of two.
132 >     * Should be small because backoffs exponentially increase from base.
133 >     * The value should be close to the round-trip time of a call to
134 >     * LockSupport.park in the case where some other thread has already
135 >     * called unpark.  On multiprocessors, timed waits less than this value
136 >     * are implemented by spinning.
137       */
138      static final long BACKOFF_BASE = (1L << 6);
139  
# Line 142 | Line 142 | public class Exchanger<V> {
142       * than to use timed park. Should normally be zero on
143       * uniprocessors and BACKOFF_BASE on multiprocessors.
144       */
145 <    static final long spinForTimeoutThreshold = (NCPUS < 2)? 0 : BACKOFF_BASE;
145 >    static final long spinForTimeoutThreshold = (NCPUS < 2) ? 0 : BACKOFF_BASE;
146  
147      /**
148       * The number of times to spin before blocking in timed waits.
149       * The value is empirically derived -- it works well across a
150 <     * variety of processors and OSes. Empirically, the best value
150 >     * variety of processors and OSes.  Empirically, the best value
151       * seems not to vary with number of CPUs (beyond 2) so is just
152       * a constant.
153       */
154 <    static final int maxTimedSpins = (NCPUS < 2)? 0 : 16;
154 >    static final int maxTimedSpins = (NCPUS < 2) ? 0 : 16;
155  
156      /**
157       * The number of times to spin before blocking in untimed waits.
# Line 174 | Line 174 | public class Exchanger<V> {
174      private final AtomicReference<Node>[] arena;
175  
176      /**
177 <     * Per-thread random number generator. Because random numbers are
178 <     * used to choose slots and delays to reduce contention, the
177 >     * Per-thread random number generator.  Because random numbers
178 >     * are used to choose slots and delays to reduce contention, the
179       * random number generator itself cannot introduce contention.
180       * And the statistical quality of the generator is not too
181 <     * important. So we use a custom cheap generator, and maintain it
182 <     * as a thread local.
181 >     * important.  So we use a custom cheap generator, and maintain
182 >     * it as a thread local.
183       */
184      private static final ThreadLocal<RNG> random = new ThreadLocal<RNG>() {
185          public RNG initialValue() { return new RNG(); } };
# Line 255 | Line 255 | public class Exchanger<V> {
255              }
256  
257              // Retry with a random non-top slot <= backoff
258 <            idx = backoff == 0? 1 : 1 + random.get().next() % (backoff + 1);
258 >            idx = backoff == 0 ? 1 : 1 + random.get().next() % (backoff + 1);
259          }
260      }
261  
# Line 292 | Line 292 | public class Exchanger<V> {
292          }
293  
294          /**
295 <         * Unparks thread if it is waiting
295 >         * Unparks thread if it is waiting.
296           */
297          void signal() {
298              LockSupport.unpark(waiter);
# Line 308 | Line 308 | public class Exchanger<V> {
308           */
309          Object waitForHole(boolean timed, long nanos) {
310              long lastTime = timed ? System.nanoTime() : 0;
311 <            int spins = timed? maxTimedSpins : maxUntimedSpins;
311 >            int spins = timed ? maxTimedSpins : maxUntimedSpins;
312              Thread w = Thread.currentThread();
313              for (;;) {
314                  if (w.isInterrupted())

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines