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

Comparing jsr166/src/main/java/util/concurrent/SynchronousQueue.java (file contents):
Revision 1.71 by jsr166, Mon Sep 27 19:15:15 2010 UTC vs.
Revision 1.72 by jsr166, Fri Oct 22 05:18:31 2010 UTC

# Line 161 | Line 161 | public class SynchronousQueue<E> extends
161       * seems not to vary with number of CPUs (beyond 2) so is just
162       * a constant.
163       */
164 <    static final int maxTimedSpins = (NCPUS < 2)? 0 : 32;
164 >    static final int maxTimedSpins = (NCPUS < 2) ? 0 : 32;
165  
166      /**
167       * The number of times to spin before blocking in untimed waits.
# Line 306 | Line 306 | public class SynchronousQueue<E> extends
306               */
307  
308              SNode s = null; // constructed/reused as needed
309 <            int mode = (e == null)? REQUEST : DATA;
309 >            int mode = (e == null) ? REQUEST : DATA;
310  
311              for (;;) {
312                  SNode h = head;
# Line 324 | Line 324 | public class SynchronousQueue<E> extends
324                          }
325                          if ((h = head) != null && h.next == s)
326                              casHead(h, s.next);     // help s's fulfiller
327 <                        return mode == REQUEST? m.item : s.item;
327 >                        return (mode == REQUEST) ? m.item : s.item;
328                      }
329                  } else if (!isFulfilling(h.mode)) { // try to fulfill
330                      if (h.isCancelled())            // already cancelled
# Line 340 | Line 340 | public class SynchronousQueue<E> extends
340                              SNode mn = m.next;
341                              if (m.tryMatch(s)) {
342                                  casHead(s, mn);     // pop both s and m
343 <                                return (mode == REQUEST)? m.item : s.item;
343 >                                return (mode == REQUEST) ? m.item : s.item;
344                              } else                  // lost match
345                                  s.casNext(m, mn);   // help unlink
346                          }
# Line 391 | Line 391 | public class SynchronousQueue<E> extends
391               * and don't wait at all, so are trapped in transfer
392               * method rather than calling awaitFulfill.
393               */
394 <            long lastTime = (timed)? System.nanoTime() : 0;
394 >            long lastTime = timed ? System.nanoTime() : 0;
395              Thread w = Thread.currentThread();
396              SNode h = head;
397 <            int spins = (shouldSpin(s)?
398 <                         (timed? maxTimedSpins : maxUntimedSpins) : 0);
397 >            int spins = (shouldSpin(s) ?
398 >                         (timed ? maxTimedSpins : maxUntimedSpins) : 0);
399              for (;;) {
400                  if (w.isInterrupted())
401                      s.tryCancel();
# Line 412 | Line 412 | public class SynchronousQueue<E> extends
412                      }
413                  }
414                  if (spins > 0)
415 <                    spins = shouldSpin(s)? (spins-1) : 0;
415 >                    spins = shouldSpin(s) ? (spins-1) : 0;
416                  else if (s.waiter == null)
417                      s.waiter = w; // establish waiter so can park next iter
418                  else if (!timed)
# Line 645 | Line 645 | public class SynchronousQueue<E> extends
645                              s.item = s;
646                          s.waiter = null;
647                      }
648 <                    return (x != null)? x : e;
648 >                    return (x != null) ? x : e;
649  
650                  } else {                            // complementary-mode
651                      QNode m = h.next;               // node to fulfill
# Line 662 | Line 662 | public class SynchronousQueue<E> extends
662  
663                      advanceHead(h, m);              // successfully fulfilled
664                      LockSupport.unpark(m.waiter);
665 <                    return (x != null)? x : e;
665 >                    return (x != null) ? x : e;
666                  }
667              }
668          }
# Line 678 | Line 678 | public class SynchronousQueue<E> extends
678           */
679          Object awaitFulfill(QNode s, Object e, boolean timed, long nanos) {
680              /* Same idea as TransferStack.awaitFulfill */
681 <            long lastTime = (timed)? System.nanoTime() : 0;
681 >            long lastTime = timed ? System.nanoTime() : 0;
682              Thread w = Thread.currentThread();
683              int spins = ((head.next == s) ?
684 <                         (timed? maxTimedSpins : maxUntimedSpins) : 0);
684 >                         (timed ? maxTimedSpins : maxUntimedSpins) : 0);
685              for (;;) {
686                  if (w.isInterrupted())
687                      s.tryCancel(e);
# Line 796 | Line 796 | public class SynchronousQueue<E> extends
796       *        access; otherwise the order is unspecified.
797       */
798      public SynchronousQueue(boolean fair) {
799 <        transferer = (fair)? new TransferQueue() : new TransferStack();
799 >        transferer = fair ? new TransferQueue() : new TransferStack();
800      }
801  
802      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines