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.41 by jsr166, Sat Aug 1 20:44:05 2009 UTC vs.
Revision 1.44 by jsr166, Tue Aug 4 20:32:16 2009 UTC

# Line 18 | Line 18 | import java.util.concurrent.locks.LockSu
18   import java.util.concurrent.atomic.AtomicReference;
19  
20   /**
21 < * An unbounded {@linkplain TransferQueue} based on linked nodes.
21 > * An unbounded {@link TransferQueue} based on linked nodes.
22   * This queue orders elements FIFO (first-in-first-out) with respect
23   * to any given producer.  The <em>head</em> of the queue is that
24   * element that has been on the queue the longest time for some
# Line 219 | Line 219 | public class LinkedTransferQueue<E> exte
219              Node<E> t = tail.get();
220              Node<E> h = head.get();
221  
222 <            if (t != null && (t == h || t.isData == isData)) {
222 >            if (t == h || t.isData == isData) {
223                  if (s == null)
224                      s = new Node<E>(e, isData);
225                  Node<E> last = t.next;
# Line 231 | Line 231 | public class LinkedTransferQueue<E> exte
231                      tail.compareAndSet(t, s);
232                      return awaitFulfill(t, s, e, mode, nanos);
233                  }
234 <            }
235 <
236 <            else if (h != null) {
234 >            } else {
235                  Node<E> first = h.next;
236                  if (t == tail.get() && first != null &&
237                      advanceHead(h, first)) {
# Line 261 | Line 259 | public class LinkedTransferQueue<E> exte
259              Node<E> t = tail.get();
260              Node<E> h = head.get();
261  
262 <            if (t != null && (t == h || t.isData == isData)) {
262 >            if (t == h || t.isData == isData) {
263                  Node<E> last = t.next;
264                  if (t == tail.get()) {
265                      if (last != null)
# Line 269 | Line 267 | public class LinkedTransferQueue<E> exte
267                      else
268                          return null;
269                  }
270 <            }
273 <            else if (h != null) {
270 >            } else {
271                  Node<E> first = h.next;
272                  if (t == tail.get() &&
273                      first != null &&
# Line 332 | Line 329 | public class LinkedTransferQueue<E> exte
329              }
330              if (spins < 0) {
331                  Node<E> h = head.get(); // only spin if at head
332 <                spins = ((h != null && h.next == s) ?
333 <                         ((mode == TIMEOUT) ?
334 <                          maxTimedSpins : maxUntimedSpins) : 0);
332 >                spins = ((h.next != s) ? 0 :
333 >                         (mode == TIMEOUT) ? maxTimedSpins :
334 >                         maxUntimedSpins);
335              }
336              if (spins > 0)
337                  --spins;
# Line 643 | Line 640 | public class LinkedTransferQueue<E> exte
640          for (;;) {
641              Node<E> t = tail.get();
642              Node<E> h = head.get();
643 <            if (h != null && t != null) {
644 <                Node<E> last = t.next;
645 <                Node<E> first = h.next;
646 <                if (t == tail.get()) {
647 <                    if (last != null)
648 <                        tail.compareAndSet(t, last);
649 <                    else if (first != null) {
650 <                        Object x = first.get();
651 <                        if (x == first)
655 <                            advanceHead(h, first);
656 <                        else
657 <                            return h;
658 <                    }
643 >            Node<E> last = t.next;
644 >            Node<E> first = h.next;
645 >            if (t == tail.get()) {
646 >                if (last != null)
647 >                    tail.compareAndSet(t, last);
648 >                else if (first != null) {
649 >                    Object x = first.get();
650 >                    if (x == first)
651 >                        advanceHead(h, first);
652                      else
653                          return h;
654                  }
655 +                else
656 +                    return h;
657              }
658              reclean();
659          }
# Line 848 | Line 843 | public class LinkedTransferQueue<E> exte
843          }
844      }
845  
846 +    /**
847 +     * Removes a single instance of the specified element from this queue,
848 +     * if it is present.  More formally, removes an element {@code e} such
849 +     * that {@code o.equals(e)}, if this queue contains one or more such
850 +     * elements.
851 +     * Returns {@code true} if this queue contained the specified element
852 +     * (or equivalently, if this queue changed as a result of the call).
853 +     *
854 +     * @param o element to be removed from this queue, if present
855 +     * @return {@code true} if this queue changed as a result of the call
856 +     */
857      public boolean remove(Object o) {
858          if (o == null)
859              return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines