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

Comparing jsr166/src/main/java/util/concurrent/ConcurrentLinkedDeque.java (file contents):
Revision 1.8 by jsr166, Sun Sep 12 00:34:46 2010 UTC vs.
Revision 1.9 by jsr166, Sun Sep 12 19:36:42 2010 UTC

# Line 493 | Line 493 | public class ConcurrentLinkedDeque<E>
493       * Unlinks non-null first node.
494       */
495      private void unlinkFirst(Node<E> first, Node<E> next) {
496 <        // assert first != null && next != null && first.item == null;
496 >        // assert first != null;
497 >        // assert next != null;
498 >        // assert first.item == null;
499          Node<E> o = null, p = next;
500          for (int hops = 0; ; ++hops) {
501              Node<E> q;
# Line 527 | Line 529 | public class ConcurrentLinkedDeque<E>
529       * Unlinks non-null last node.
530       */
531      private void unlinkLast(Node<E> last, Node<E> prev) {
532 <        // assert last != null && prev != null && last.item == null;
532 >        // assert last != null;
533 >        // assert prev != null;
534 >        // assert last.item == null;
535          Node<E> o = null, p = prev;
536          for (int hops = 0; ; ++hops) {
537              Node<E> q;
# Line 785 | Line 789 | public class ConcurrentLinkedDeque<E>
789                  t = newNode;
790              }
791          }
792 <        if (h == null)
793 <            h = t = new Node<E>(null);
792 >        initHeadTail(h, t);
793 >    }
794 >
795 >    /**
796 >     * Initializes head and tail, ensuring invariants hold.
797 >     */
798 >    private void initHeadTail(Node<E> h, Node<E> t) {
799 >        if (h == t) {
800 >            if (h == null)
801 >                h = t = new Node<E>(null);
802 >            else {
803 >                // Avoid edge case of a single Node with non-null item.
804 >                Node<E> newNode = new Node<E>(null);
805 >                t.lazySetNext(newNode);
806 >                newNode.lazySetPrev(t);
807 >                t = newNode;
808 >            }
809 >        }
810          head = h;
811          tail = t;
812      }
# Line 1332 | Line 1352 | public class ConcurrentLinkedDeque<E>
1352                  t = newNode;
1353              }
1354          }
1355 <        if (h == null)
1336 <            h = t = new Node<E>(null);
1337 <        head = h;
1338 <        tail = t;
1355 >        initHeadTail(h, t);
1356      }
1357  
1358      // Unsafe mechanics

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines