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

Comparing jsr166/src/jsr166y/LinkedTransferQueue.java (file contents):
Revision 1.20 by jsr166, Tue Jul 21 18:11:44 2009 UTC vs.
Revision 1.23 by jsr166, Thu Jul 23 23:07:57 2009 UTC

# Line 44 | Line 44 | import java.lang.reflect.*;
44   * @since 1.7
45   * @author Doug Lea
46   * @param <E> the type of elements held in this collection
47 *
47   */
48   public class LinkedTransferQueue<E> extends AbstractQueue<E>
49      implements TransferQueue<E>, java.io.Serializable {
# Line 81 | Line 80 | public class LinkedTransferQueue<E> exte
80       * seems not to vary with number of CPUs (beyond 2) so is just
81       * a constant.
82       */
83 <    static final int maxTimedSpins = (NCPUS < 2)? 0 : 32;
83 >    static final int maxTimedSpins = (NCPUS < 2) ? 0 : 32;
84  
85      /**
86       * The number of times to spin before blocking in untimed waits.
# Line 140 | Line 139 | public class LinkedTransferQueue<E> exte
139  
140      /** head of the queue */
141      private transient final PaddedAtomicReference<QNode> head;
142 +
143      /** tail of the queue */
144      private transient final PaddedAtomicReference<QNode> tail;
145  
# Line 203 | Line 203 | public class LinkedTransferQueue<E> exte
203                      Object x = first.get();
204                      if (x != first && first.compareAndSet(x, e)) {
205                          LockSupport.unpark(first.waiter);
206 <                        return isData? e : x;
206 >                        return isData ? e : x;
207                      }
208                  }
209              }
# Line 241 | Line 241 | public class LinkedTransferQueue<E> exte
241                      Object x = first.get();
242                      if (x != first && first.compareAndSet(x, e)) {
243                          LockSupport.unpark(first.waiter);
244 <                        return isData? e : x;
244 >                        return isData ? e : x;
245                      }
246                  }
247              }
# Line 264 | Line 264 | public class LinkedTransferQueue<E> exte
264          if (mode == NOWAIT)
265              return null;
266  
267 <        long lastTime = (mode == TIMEOUT)? System.nanoTime() : 0;
267 >        long lastTime = (mode == TIMEOUT) ? System.nanoTime() : 0;
268          Thread w = Thread.currentThread();
269          int spins = -1; // set to desired spin count below
270          for (;;) {
# Line 296 | Line 296 | public class LinkedTransferQueue<E> exte
296              if (spins < 0) {
297                  QNode h = head.get(); // only spin if at head
298                  spins = ((h != null && h.next == s) ?
299 <                         (mode == TIMEOUT?
299 >                         ((mode == TIMEOUT) ?
300                            maxTimedSpins : maxUntimedSpins) : 0);
301              }
302              if (spins > 0)
# Line 487 | Line 487 | public class LinkedTransferQueue<E> exte
487      public E take() throws InterruptedException {
488          Object e = xfer(null, WAIT, 0);
489          if (e != null)
490 <            return (E)e;
490 >            return (E) e;
491          Thread.interrupted();
492          throw new InterruptedException();
493      }
# Line 495 | Line 495 | public class LinkedTransferQueue<E> exte
495      public E poll(long timeout, TimeUnit unit) throws InterruptedException {
496          Object e = xfer(null, TIMEOUT, unit.toNanos(timeout));
497          if (e != null || !Thread.interrupted())
498 <            return (E)e;
498 >            return (E) e;
499          throw new InterruptedException();
500      }
501  
502      public E poll() {
503 <        return (E)fulfill(null);
503 >        return (E) fulfill(null);
504      }
505  
506      public int drainTo(Collection<? super E> c) {
# Line 603 | Line 603 | public class LinkedTransferQueue<E> exte
603                  Object x = q.get();
604                  QNode s = q.next;
605                  if (x != null && q != x && q != s) {
606 <                    nextItem = (E)x;
606 >                    nextItem = (E) x;
607                      snext = s;
608                      pnext = pred;
609                      next = q;
# Line 650 | Line 650 | public class LinkedTransferQueue<E> exte
650                  if (!p.isData)
651                      return null;
652                  if (x != null)
653 <                    return (E)x;
653 >                    return (E) x;
654              }
655          }
656      }
# Line 773 | Line 773 | public class LinkedTransferQueue<E> exte
773          s.defaultReadObject();
774          resetHeadAndTail();
775          for (;;) {
776 <            E item = (E)s.readObject();
776 >            E item = (E) s.readObject();
777              if (item == null)
778                  break;
779              else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines