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

Comparing jsr166/src/main/java/util/concurrent/LinkedStack.java (file contents):
Revision 1.1 by dl, Sun Jun 22 14:27:18 2003 UTC vs.
Revision 1.2 by dl, Tue Jun 24 14:34:48 2003 UTC

# Line 27 | Line 27 | import java.util.concurrent.atomic.*;
27   * method is <em>NOT</em> a constant-time operation. Because of the
28   * asynchronous nature of these stacks, determining the current number
29   * of elements requires an O(n) traversal.
30 < **/
30 > * @since 1.5
31 > * @author Doug Lea
32 > **/
33  
34   public class LinkedStack<E> extends AbstractQueue<E>
35          implements Queue<E>, java.io.Serializable {
# Line 44 | Line 46 | public class LinkedStack<E> extends Abst
46       * so all traversals must detect and relink lingering nulls.
47       */
48  
49 +    /** Head of the linked list */
50      private transient volatile AtomicLinkedNode head;
51  
52 <    private final static AtomicReferenceFieldUpdater<LinkedStack, AtomicLinkedNode> headUpdater = new AtomicReferenceFieldUpdater<LinkedStack, AtomicLinkedNode>(new LinkedStack[0], new AtomicLinkedNode[0], "head");
52 >    private static final AtomicReferenceFieldUpdater<LinkedStack, AtomicLinkedNode> headUpdater = new AtomicReferenceFieldUpdater<LinkedStack, AtomicLinkedNode>(new LinkedStack[0], new AtomicLinkedNode[0], "head");
53  
54      private boolean casHead(AtomicLinkedNode cmp, AtomicLinkedNode val) {
55          return headUpdater.compareAndSet(this, cmp, val);
# Line 98 | Line 101 | public class LinkedStack<E> extends Abst
101       * Pushes the given element on the stack.
102       * @param x the element to insert
103       * @return true -- (as per the general contract of Queue.offer).
104 <     * @throws IllegalArgumentException if x is null
104 >     * @throws NullPointerException if x is null
105       **/
106      public boolean offer(E x) {
107 <        if (x == null) throw new IllegalArgumentException();
107 >        if (x == null) throw new NullPointerException();
108          AtomicLinkedNode p = new AtomicLinkedNode(x);
109          for (;;) {
110              AtomicLinkedNode h = head;
# Line 326 | Line 329 | public class LinkedStack<E> extends Abst
329              lastRet = nextNode;
330              E x = nextItem;
331              
332 <            AtomicLinkedNode p = (nextNode == null)? head : nextNode.getNext();
332 >            AtomicLinkedNode p = (nextNode == null) ? head : nextNode.getNext();
333              for (;;) {
334                  if (p == null) {
335                      nextNode = null;
# Line 371 | Line 374 | public class LinkedStack<E> extends Abst
374       *
375       * @serialData All of the elements (each an <tt>E</tt>) in
376       * the proper order, followed by a null
377 +     * @param s the stream
378       */
379      private void writeObject(java.io.ObjectOutputStream s)
380          throws java.io.IOException {
# Line 398 | Line 402 | public class LinkedStack<E> extends Abst
402      /**
403       * Reconstitute the Queue instance from a stream (that is,
404       * deserialize it).
405 +     * @param s the stream
406       */
407      private void readObject(java.io.ObjectInputStream s)
408          throws java.io.IOException, ClassNotFoundException {
409 <        // Read in capacity, and any hidden stuff
410 <        s.defaultReadObject();
409 >        // Read in capacity, and any hidden stuff
410 >        s.defaultReadObject();
411  
412 <        // Read in all elements into array and then insert in reverse order.
412 >        // Read in all elements into array and then insert in reverse order.
413          ArrayList<E> al = new ArrayList<E>();
414          for (;;) {
415              E item = (E)s.readObject();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines