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.9 by dl, Sun Nov 16 20:24:54 2008 UTC vs.
Revision 1.12 by dl, Mon Jan 12 17:16:18 2009 UTC

# Line 21 | Line 21 | import java.lang.reflect.*;
21   * producer.  The <em>tail</em> of the queue is that element that has
22   * been on the queue the shortest time for some producer.
23   *
24 < * <p>Beware that, unlike in most collections, the <tt>size</tt>
24 > * <p>Beware that, unlike in most collections, the {@code size}
25   * method is <em>NOT</em> a constant-time operation. Because of the
26   * asynchronous nature of these queues, determining the current number
27   * of elements requires a traversal of the elements.
# Line 298 | Line 298 | public class LinkedTransferQueue<E> exte
298              else if (s.waiter == null)
299                  s.waiter = w;
300              else if (mode != TIMEOUT) {
301 <                //                LockSupport.park(this);
302 <                LockSupport.park(); // allows run on java5
301 >                LockSupport.park(this);
302                  s.waiter = null;
303                  spins = -1;
304              }
305              else if (nanos > spinForTimeoutThreshold) {
306 <                //                LockSupport.parkNanos(this, nanos);
308 <                LockSupport.parkNanos(nanos);
306 >                LockSupport.parkNanos(this, nanos);
307                  s.waiter = null;
308                  spins = -1;
309              }
# Line 332 | Line 330 | public class LinkedTransferQueue<E> exte
330                      return t;
331              }
332          }
333 <    }    
333 >    }
334  
335      /**
336       * Gets rid of cancelled node s with original predecessor pred.
# Line 359 | Line 357 | public class LinkedTransferQueue<E> exte
357              QNode t = getValidatedTail();
358              if (s != t) {               // If not tail, try to unsplice
359                  QNode sn = s.next;      // s.next == s means s already off list
360 <                if (sn == s || pred.casNext(s, sn))
360 >                if (sn == s || pred.casNext(s, sn))
361                      break;
362              }
363              else if (oldpred == pred || // Already saved
# Line 374 | Line 372 | public class LinkedTransferQueue<E> exte
372       * @return current cleanMe node (or null)
373       */
374      private QNode reclean() {
375 <        /*
375 >        /*
376           * cleanMe is, or at one time was, predecessor of cancelled
377           * node s that was the tail so could not be unspliced.  If s
378           * is no longer the tail, try to unsplice if necessary and
# Line 383 | Line 381 | public class LinkedTransferQueue<E> exte
381           * points to a cancelled node that must be unspliced -- if
382           * not, we can (must) clear cleanMe without unsplicing.
383           * This can loop only due to contention on casNext or
384 <         * clearing cleanMe.
384 >         * clearing cleanMe.
385           */
386          QNode pred;
387          while ((pred = cleanMe.get()) != null) {
388              QNode t = getValidatedTail();
389              QNode s = pred.next;
390 <            if (s != t) {
390 >            if (s != t) {
391                  QNode sn;
392                  if (s == null || s == pred || s.get() != s ||
393                      (sn = s.next) == s || pred.casNext(s, sn))
# Line 402 | Line 400 | public class LinkedTransferQueue<E> exte
400      }
401  
402      /**
403 <     * Creates an initially empty <tt>LinkedTransferQueue</tt>.
403 >     * Creates an initially empty {@code LinkedTransferQueue}.
404       */
405      public LinkedTransferQueue() {
406          QNode dummy = new QNode(null, false);
# Line 412 | Line 410 | public class LinkedTransferQueue<E> exte
410      }
411  
412      /**
413 <     * Creates a <tt>LinkedTransferQueue</tt>
413 >     * Creates a {@code LinkedTransferQueue}
414       * initially containing the elements of the given collection,
415       * added in traversal order of the collection's iterator.
416       * @param c the collection of elements to initially contain
# Line 655 | Line 653 | public class LinkedTransferQueue<E> exte
653  
654      /**
655       * Returns the number of elements in this queue.  If this queue
656 <     * contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
657 <     * <tt>Integer.MAX_VALUE</tt>.
656 >     * contains more than {@code Integer.MAX_VALUE} elements, returns
657 >     * {@code Integer.MAX_VALUE}.
658       *
659       * <p>Beware that, unlike in most collections, this method is
660       * <em>NOT</em> a constant-time operation. Because of the
# Line 697 | Line 695 | public class LinkedTransferQueue<E> exte
695      /**
696       * Save the state to a stream (that is, serialize it).
697       *
698 <     * @serialData All of the elements (each an <tt>E</tt>) in
698 >     * @serialData All of the elements (each an {@code E}) in
699       * the proper order, followed by a null
700       * @param s the stream
701       */
# Line 730 | Line 728 | public class LinkedTransferQueue<E> exte
728  
729  
730      // Support for resetting head/tail while deserializing
731 +    private void resetHeadAndTail() {
732 +        QNode dummy = new QNode(null, false);
733 +        _unsafe.putObjectVolatile(this, headOffset,
734 +                                  new PaddedAtomicReference<QNode>(dummy));
735 +        _unsafe.putObjectVolatile(this, tailOffset,
736 +                                  new PaddedAtomicReference<QNode>(dummy));
737 +        _unsafe.putObjectVolatile(this, cleanMeOffset,
738 +                                  new PaddedAtomicReference<QNode>(null));
739 +    }
740  
741      // Temporary Unsafe mechanics for preliminary release
742      private static final Unsafe _unsafe;
# Line 756 | Line 763 | public class LinkedTransferQueue<E> exte
763          }
764      }
765  
759    private void resetHeadAndTail() {
760        QNode dummy = new QNode(null, false);
761        _unsafe.putObjectVolatile(this, headOffset,
762                                  new PaddedAtomicReference<QNode>(dummy));
763        _unsafe.putObjectVolatile(this, tailOffset,
764                                  new PaddedAtomicReference<QNode>(dummy));
765        _unsafe.putObjectVolatile(this, cleanMeOffset,
766                                  new PaddedAtomicReference<QNode>(null));
767
768    }
769
766   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines