author | dl |
Tue, 28 Jul 2009 13:24:52 -0700 | |
changeset 3414 | cdf768813b4d |
parent 2 | 90ce3da70b43 |
child 3419 | 3ae6dc68c20d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
6 |
* published by the Free Software Foundation. Sun designates this |
|
7 |
* particular file as subject to the "Classpath" exception as provided |
|
8 |
* by Sun in the LICENSE file that accompanied this code. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
20 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
21 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
22 |
* have any questions. |
|
23 |
*/ |
|
24 |
||
25 |
/* |
|
26 |
* This file is available under and governed by the GNU General Public |
|
27 |
* License version 2 only, as published by the Free Software Foundation. |
|
28 |
* However, the following notice accompanied the original version of this |
|
29 |
* file: |
|
30 |
* |
|
31 |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
|
32 |
* Expert Group and released to the public domain, as explained at |
|
33 |
* http://creativecommons.org/licenses/publicdomain |
|
34 |
*/ |
|
35 |
||
36 |
package java.util.concurrent; |
|
37 |
||
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
38 |
import java.util.AbstractQueue; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
39 |
import java.util.ArrayList; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
40 |
import java.util.Collection; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
41 |
import java.util.Iterator; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
42 |
import java.util.NoSuchElementException; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
43 |
import java.util.Queue; |
2 | 44 |
|
45 |
/** |
|
46 |
* An unbounded thread-safe {@linkplain Queue queue} based on linked nodes. |
|
47 |
* This queue orders elements FIFO (first-in-first-out). |
|
48 |
* The <em>head</em> of the queue is that element that has been on the |
|
49 |
* queue the longest time. |
|
50 |
* The <em>tail</em> of the queue is that element that has been on the |
|
51 |
* queue the shortest time. New elements |
|
52 |
* are inserted at the tail of the queue, and the queue retrieval |
|
53 |
* operations obtain elements at the head of the queue. |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
54 |
* A {@code ConcurrentLinkedQueue} is an appropriate choice when |
2 | 55 |
* many threads will share access to a common collection. |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
56 |
* This queue does not permit {@code null} elements. |
2 | 57 |
* |
58 |
* <p>This implementation employs an efficient "wait-free" |
|
59 |
* algorithm based on one described in <a |
|
60 |
* href="http://www.cs.rochester.edu/u/michael/PODC96.html"> Simple, |
|
61 |
* Fast, and Practical Non-Blocking and Blocking Concurrent Queue |
|
62 |
* Algorithms</a> by Maged M. Michael and Michael L. Scott. |
|
63 |
* |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
64 |
* <p>Beware that, unlike in most collections, the {@code size} method |
2 | 65 |
* is <em>NOT</em> a constant-time operation. Because of the |
66 |
* asynchronous nature of these queues, determining the current number |
|
67 |
* of elements requires a traversal of the elements. |
|
68 |
* |
|
69 |
* <p>This class and its iterator implement all of the |
|
70 |
* <em>optional</em> methods of the {@link Collection} and {@link |
|
71 |
* Iterator} interfaces. |
|
72 |
* |
|
73 |
* <p>Memory consistency effects: As with other concurrent |
|
74 |
* collections, actions in a thread prior to placing an object into a |
|
75 |
* {@code ConcurrentLinkedQueue} |
|
76 |
* <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a> |
|
77 |
* actions subsequent to the access or removal of that element from |
|
78 |
* the {@code ConcurrentLinkedQueue} in another thread. |
|
79 |
* |
|
80 |
* <p>This class is a member of the |
|
81 |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
|
82 |
* Java Collections Framework</a>. |
|
83 |
* |
|
84 |
* @since 1.5 |
|
85 |
* @author Doug Lea |
|
86 |
* @param <E> the type of elements held in this collection |
|
87 |
* |
|
88 |
*/ |
|
89 |
public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> |
|
90 |
implements Queue<E>, java.io.Serializable { |
|
91 |
private static final long serialVersionUID = 196745693267521676L; |
|
92 |
||
93 |
/* |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
94 |
* This is a modification of the Michael & Scott algorithm, |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
95 |
* adapted for a garbage-collected environment, with support for |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
96 |
* interior node deletion (to support remove(Object)). For |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
97 |
* explanation, read the paper. |
2 | 98 |
* |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
99 |
* Note that like most non-blocking algorithms in this package, |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
100 |
* this implementation relies on the fact that in garbage |
2 | 101 |
* collected systems, there is no possibility of ABA problems due |
102 |
* to recycled nodes, so there is no need to use "counted |
|
103 |
* pointers" or related techniques seen in versions used in |
|
104 |
* non-GC'ed settings. |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
105 |
* |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
106 |
* The fundamental invariants are: |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
107 |
* - There is exactly one (last) Node with a null next reference, |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
108 |
* which is CASed when enqueueing. This last Node can be |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
109 |
* reached in O(1) time from tail, but tail is merely an |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
110 |
* optimization - it can always be reached in O(N) time from |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
111 |
* head as well. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
112 |
* - The elements contained in the queue are the non-null items in |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
113 |
* Nodes that are reachable from head. CASing the item |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
114 |
* reference of a Node to null atomically removes it from the |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
115 |
* queue. Reachability of all elements from head must remain |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
116 |
* true even in the case of concurrent modifications that cause |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
117 |
* head to advance. A dequeued Node may remain in use |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
118 |
* indefinitely due to creation of an Iterator or simply a |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
119 |
* poll() that has lost its time slice. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
120 |
* |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
121 |
* The above might appear to imply that all Nodes are GC-reachable |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
122 |
* from a predecessor dequeued Node. That would cause two problems: |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
123 |
* - allow a rogue Iterator to cause unbounded memory retention |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
124 |
* - cause cross-generational linking of old Nodes to new Nodes if |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
125 |
* a Node was tenured while live, which generational GCs have a |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
126 |
* hard time dealing with, causing repeated major collections. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
127 |
* However, only non-deleted Nodes need to be reachable from |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
128 |
* dequeued Nodes, and reachability does not necessarily have to |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
129 |
* be of the kind understood by the GC. We use the trick of |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
130 |
* linking a Node that has just been dequeued to itself. Such a |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
131 |
* self-link implicitly means to advance to head. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
132 |
* |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
133 |
* Both head and tail are permitted to lag. In fact, failing to |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
134 |
* update them every time one could is a significant optimization |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
135 |
* (fewer CASes). This is controlled by local "hops" variables |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
136 |
* that only trigger helping-CASes after experiencing multiple |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
137 |
* lags. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
138 |
* |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
139 |
* Since head and tail are updated concurrently and independently, |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
140 |
* it is possible for tail to lag behind head (why not)? |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
141 |
* |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
142 |
* CASing a Node's item reference to null atomically removes the |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
143 |
* element from the queue. Iterators skip over Nodes with null |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
144 |
* items. Prior implementations of this class had a race between |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
145 |
* poll() and remove(Object) where the same element would appear |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
146 |
* to be successfully removed by two concurrent operations. The |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
147 |
* method remove(Object) also lazily unlinks deleted Nodes, but |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
148 |
* this is merely an optimization. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
149 |
* |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
150 |
* When constructing a Node (before enqueuing it) we avoid paying |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
151 |
* for a volatile write to item by using lazySet instead of a |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
152 |
* normal write. This allows the cost of enqueue to be |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
153 |
* "one-and-a-half" CASes. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
154 |
* |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
155 |
* Both head and tail may or may not point to a Node with a |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
156 |
* non-null item. If the queue is empty, all items must of course |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
157 |
* be null. Upon creation, both head and tail refer to a dummy |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
158 |
* Node with null item. Both head and tail are only updated using |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
159 |
* CAS, so they never regress, although again this is merely an |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
160 |
* optimization. |
2 | 161 |
*/ |
162 |
||
163 |
private static class Node<E> { |
|
164 |
private volatile E item; |
|
165 |
private volatile Node<E> next; |
|
166 |
||
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
167 |
Node(E item) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
168 |
// Piggyback on imminent casNext() |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
169 |
lazySetItem(item); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
170 |
} |
2 | 171 |
|
172 |
E getItem() { |
|
173 |
return item; |
|
174 |
} |
|
175 |
||
176 |
boolean casItem(E cmp, E val) { |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
177 |
return UNSAFE.compareAndSwapObject(this, itemOffset, cmp, val); |
2 | 178 |
} |
179 |
||
180 |
void setItem(E val) { |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
181 |
item = val; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
182 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
183 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
184 |
void lazySetItem(E val) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
185 |
UNSAFE.putOrderedObject(this, itemOffset, val); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
186 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
187 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
188 |
void lazySetNext(Node<E> val) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
189 |
UNSAFE.putOrderedObject(this, nextOffset, val); |
2 | 190 |
} |
191 |
||
192 |
Node<E> getNext() { |
|
193 |
return next; |
|
194 |
} |
|
195 |
||
196 |
boolean casNext(Node<E> cmp, Node<E> val) { |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
197 |
return UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val); |
2 | 198 |
} |
199 |
||
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
200 |
// Unsafe mechanics |
2 | 201 |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
202 |
private static final sun.misc.Unsafe UNSAFE = |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
203 |
sun.misc.Unsafe.getUnsafe(); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
204 |
private static final long nextOffset = |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
205 |
objectFieldOffset(UNSAFE, "next", Node.class); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
206 |
private static final long itemOffset = |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
207 |
objectFieldOffset(UNSAFE, "item", Node.class); |
2 | 208 |
} |
209 |
||
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
210 |
/** |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
211 |
* A node from which the first live (non-deleted) node (if any) |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
212 |
* can be reached in O(1) time. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
213 |
* Invariants: |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
214 |
* - all live nodes are reachable from head via succ() |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
215 |
* - head != null |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
216 |
* - (tmp = head).next != tmp || tmp != head |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
217 |
* Non-invariants: |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
218 |
* - head.item may or may not be null. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
219 |
* - it is permitted for tail to lag behind head, that is, for tail |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
220 |
* to not be reachable from head! |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
221 |
*/ |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
222 |
private transient volatile Node<E> head = new Node<E>(null); |
2 | 223 |
|
224 |
/** |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
225 |
* A node from which the last node on list (that is, the unique |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
226 |
* node with node.next == null) can be reached in O(1) time. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
227 |
* Invariants: |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
228 |
* - the last node is always reachable from tail via succ() |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
229 |
* - tail != null |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
230 |
* Non-invariants: |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
231 |
* - tail.item may or may not be null. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
232 |
* - it is permitted for tail to lag behind head, that is, for tail |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
233 |
* to not be reachable from head! |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
234 |
* - tail.next may or may not be self-pointing to tail. |
2 | 235 |
*/ |
236 |
private transient volatile Node<E> tail = head; |
|
237 |
||
238 |
||
239 |
/** |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
240 |
* Creates a {@code ConcurrentLinkedQueue} that is initially empty. |
2 | 241 |
*/ |
242 |
public ConcurrentLinkedQueue() {} |
|
243 |
||
244 |
/** |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
245 |
* Creates a {@code ConcurrentLinkedQueue} |
2 | 246 |
* initially containing the elements of the given collection, |
247 |
* added in traversal order of the collection's iterator. |
|
248 |
* @param c the collection of elements to initially contain |
|
249 |
* @throws NullPointerException if the specified collection or any |
|
250 |
* of its elements are null |
|
251 |
*/ |
|
252 |
public ConcurrentLinkedQueue(Collection<? extends E> c) { |
|
253 |
for (Iterator<? extends E> it = c.iterator(); it.hasNext();) |
|
254 |
add(it.next()); |
|
255 |
} |
|
256 |
||
257 |
// Have to override just to update the javadoc |
|
258 |
||
259 |
/** |
|
260 |
* Inserts the specified element at the tail of this queue. |
|
261 |
* |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
262 |
* @return {@code true} (as specified by {@link Collection#add}) |
2 | 263 |
* @throws NullPointerException if the specified element is null |
264 |
*/ |
|
265 |
public boolean add(E e) { |
|
266 |
return offer(e); |
|
267 |
} |
|
268 |
||
269 |
/** |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
270 |
* We don't bother to update head or tail pointers if fewer than |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
271 |
* HOPS links from "true" location. We assume that volatile |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
272 |
* writes are significantly more expensive than volatile reads. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
273 |
*/ |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
274 |
private static final int HOPS = 1; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
275 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
276 |
/** |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
277 |
* Try to CAS head to p. If successful, repoint old head to itself |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
278 |
* as sentinel for succ(), below. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
279 |
*/ |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
280 |
final void updateHead(Node<E> h, Node<E> p) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
281 |
if (h != p && casHead(h, p)) |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
282 |
h.lazySetNext(h); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
283 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
284 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
285 |
/** |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
286 |
* Returns the successor of p, or the head node if p.next has been |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
287 |
* linked to self, which will only be true if traversing with a |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
288 |
* stale pointer that is now off the list. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
289 |
*/ |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
290 |
final Node<E> succ(Node<E> p) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
291 |
Node<E> next = p.getNext(); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
292 |
return (p == next) ? head : next; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
293 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
294 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
295 |
/** |
2 | 296 |
* Inserts the specified element at the tail of this queue. |
297 |
* |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
298 |
* @return {@code true} (as specified by {@link Queue#offer}) |
2 | 299 |
* @throws NullPointerException if the specified element is null |
300 |
*/ |
|
301 |
public boolean offer(E e) { |
|
302 |
if (e == null) throw new NullPointerException(); |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
303 |
Node<E> n = new Node<E>(e); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
304 |
retry: |
2 | 305 |
for (;;) { |
306 |
Node<E> t = tail; |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
307 |
Node<E> p = t; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
308 |
for (int hops = 0; ; hops++) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
309 |
Node<E> next = succ(p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
310 |
if (next != null) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
311 |
if (hops > HOPS && t != tail) |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
312 |
continue retry; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
313 |
p = next; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
314 |
} else if (p.casNext(null, n)) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
315 |
if (hops >= HOPS) |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
316 |
casTail(t, n); // Failure is OK. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
317 |
return true; |
2 | 318 |
} else { |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
319 |
p = succ(p); |
2 | 320 |
} |
321 |
} |
|
322 |
} |
|
323 |
} |
|
324 |
||
325 |
public E poll() { |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
326 |
Node<E> h = head; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
327 |
Node<E> p = h; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
328 |
for (int hops = 0; ; hops++) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
329 |
E item = p.getItem(); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
330 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
331 |
if (item != null && p.casItem(item, null)) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
332 |
if (hops >= HOPS) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
333 |
Node<E> q = p.getNext(); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
334 |
updateHead(h, (q != null) ? q : p); |
2 | 335 |
} |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
336 |
return item; |
2 | 337 |
} |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
338 |
Node<E> next = succ(p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
339 |
if (next == null) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
340 |
updateHead(h, p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
341 |
break; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
342 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
343 |
p = next; |
2 | 344 |
} |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
345 |
return null; |
2 | 346 |
} |
347 |
||
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
348 |
public E peek() { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
349 |
Node<E> h = head; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
350 |
Node<E> p = h; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
351 |
E item; |
2 | 352 |
for (;;) { |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
353 |
item = p.getItem(); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
354 |
if (item != null) |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
355 |
break; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
356 |
Node<E> next = succ(p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
357 |
if (next == null) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
358 |
break; |
2 | 359 |
} |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
360 |
p = next; |
2 | 361 |
} |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
362 |
updateHead(h, p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
363 |
return item; |
2 | 364 |
} |
365 |
||
366 |
/** |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
367 |
* Returns the first live (non-deleted) node on list, or null if none. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
368 |
* This is yet another variant of poll/peek; here returning the |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
369 |
* first node, not element. We could make peek() a wrapper around |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
370 |
* first(), but that would cost an extra volatile read of item, |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
371 |
* and the need to add a retry loop to deal with the possibility |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
372 |
* of losing a race to a concurrent poll(). |
2 | 373 |
*/ |
374 |
Node<E> first() { |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
375 |
Node<E> h = head; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
376 |
Node<E> p = h; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
377 |
Node<E> result; |
2 | 378 |
for (;;) { |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
379 |
E item = p.getItem(); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
380 |
if (item != null) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
381 |
result = p; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
382 |
break; |
2 | 383 |
} |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
384 |
Node<E> next = succ(p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
385 |
if (next == null) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
386 |
result = null; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
387 |
break; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
388 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
389 |
p = next; |
2 | 390 |
} |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
391 |
updateHead(h, p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
392 |
return result; |
2 | 393 |
} |
394 |
||
395 |
/** |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
396 |
* Returns {@code true} if this queue contains no elements. |
2 | 397 |
* |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
398 |
* @return {@code true} if this queue contains no elements |
2 | 399 |
*/ |
400 |
public boolean isEmpty() { |
|
401 |
return first() == null; |
|
402 |
} |
|
403 |
||
404 |
/** |
|
405 |
* Returns the number of elements in this queue. If this queue |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
406 |
* contains more than {@code Integer.MAX_VALUE} elements, returns |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
407 |
* {@code Integer.MAX_VALUE}. |
2 | 408 |
* |
409 |
* <p>Beware that, unlike in most collections, this method is |
|
410 |
* <em>NOT</em> a constant-time operation. Because of the |
|
411 |
* asynchronous nature of these queues, determining the current |
|
412 |
* number of elements requires an O(n) traversal. |
|
413 |
* |
|
414 |
* @return the number of elements in this queue |
|
415 |
*/ |
|
416 |
public int size() { |
|
417 |
int count = 0; |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
418 |
for (Node<E> p = first(); p != null; p = succ(p)) { |
2 | 419 |
if (p.getItem() != null) { |
420 |
// Collections.size() spec says to max out |
|
421 |
if (++count == Integer.MAX_VALUE) |
|
422 |
break; |
|
423 |
} |
|
424 |
} |
|
425 |
return count; |
|
426 |
} |
|
427 |
||
428 |
/** |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
429 |
* Returns {@code true} if this queue contains the specified element. |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
430 |
* More formally, returns {@code true} if and only if this queue contains |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
431 |
* at least one element {@code e} such that {@code o.equals(e)}. |
2 | 432 |
* |
433 |
* @param o object to be checked for containment in this queue |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
434 |
* @return {@code true} if this queue contains the specified element |
2 | 435 |
*/ |
436 |
public boolean contains(Object o) { |
|
437 |
if (o == null) return false; |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
438 |
for (Node<E> p = first(); p != null; p = succ(p)) { |
2 | 439 |
E item = p.getItem(); |
440 |
if (item != null && |
|
441 |
o.equals(item)) |
|
442 |
return true; |
|
443 |
} |
|
444 |
return false; |
|
445 |
} |
|
446 |
||
447 |
/** |
|
448 |
* Removes a single instance of the specified element from this queue, |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
449 |
* if it is present. More formally, removes an element {@code e} such |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
450 |
* that {@code o.equals(e)}, if this queue contains one or more such |
2 | 451 |
* elements. |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
452 |
* Returns {@code true} if this queue contained the specified element |
2 | 453 |
* (or equivalently, if this queue changed as a result of the call). |
454 |
* |
|
455 |
* @param o element to be removed from this queue, if present |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
456 |
* @return {@code true} if this queue changed as a result of the call |
2 | 457 |
*/ |
458 |
public boolean remove(Object o) { |
|
459 |
if (o == null) return false; |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
460 |
Node<E> pred = null; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
461 |
for (Node<E> p = first(); p != null; p = succ(p)) { |
2 | 462 |
E item = p.getItem(); |
463 |
if (item != null && |
|
464 |
o.equals(item) && |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
465 |
p.casItem(item, null)) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
466 |
Node<E> next = succ(p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
467 |
if (pred != null && next != null) |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
468 |
pred.casNext(p, next); |
2 | 469 |
return true; |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
470 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
471 |
pred = p; |
2 | 472 |
} |
473 |
return false; |
|
474 |
} |
|
475 |
||
476 |
/** |
|
477 |
* Returns an array containing all of the elements in this queue, in |
|
478 |
* proper sequence. |
|
479 |
* |
|
480 |
* <p>The returned array will be "safe" in that no references to it are |
|
481 |
* maintained by this queue. (In other words, this method must allocate |
|
482 |
* a new array). The caller is thus free to modify the returned array. |
|
483 |
* |
|
484 |
* <p>This method acts as bridge between array-based and collection-based |
|
485 |
* APIs. |
|
486 |
* |
|
487 |
* @return an array containing all of the elements in this queue |
|
488 |
*/ |
|
489 |
public Object[] toArray() { |
|
490 |
// Use ArrayList to deal with resizing. |
|
491 |
ArrayList<E> al = new ArrayList<E>(); |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
492 |
for (Node<E> p = first(); p != null; p = succ(p)) { |
2 | 493 |
E item = p.getItem(); |
494 |
if (item != null) |
|
495 |
al.add(item); |
|
496 |
} |
|
497 |
return al.toArray(); |
|
498 |
} |
|
499 |
||
500 |
/** |
|
501 |
* Returns an array containing all of the elements in this queue, in |
|
502 |
* proper sequence; the runtime type of the returned array is that of |
|
503 |
* the specified array. If the queue fits in the specified array, it |
|
504 |
* is returned therein. Otherwise, a new array is allocated with the |
|
505 |
* runtime type of the specified array and the size of this queue. |
|
506 |
* |
|
507 |
* <p>If this queue fits in the specified array with room to spare |
|
508 |
* (i.e., the array has more elements than this queue), the element in |
|
509 |
* the array immediately following the end of the queue is set to |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
510 |
* {@code null}. |
2 | 511 |
* |
512 |
* <p>Like the {@link #toArray()} method, this method acts as bridge between |
|
513 |
* array-based and collection-based APIs. Further, this method allows |
|
514 |
* precise control over the runtime type of the output array, and may, |
|
515 |
* under certain circumstances, be used to save allocation costs. |
|
516 |
* |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
517 |
* <p>Suppose {@code x} is a queue known to contain only strings. |
2 | 518 |
* The following code can be used to dump the queue into a newly |
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
519 |
* allocated array of {@code String}: |
2 | 520 |
* |
521 |
* <pre> |
|
522 |
* String[] y = x.toArray(new String[0]);</pre> |
|
523 |
* |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
524 |
* Note that {@code toArray(new Object[0])} is identical in function to |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
525 |
* {@code toArray()}. |
2 | 526 |
* |
527 |
* @param a the array into which the elements of the queue are to |
|
528 |
* be stored, if it is big enough; otherwise, a new array of the |
|
529 |
* same runtime type is allocated for this purpose |
|
530 |
* @return an array containing all of the elements in this queue |
|
531 |
* @throws ArrayStoreException if the runtime type of the specified array |
|
532 |
* is not a supertype of the runtime type of every element in |
|
533 |
* this queue |
|
534 |
* @throws NullPointerException if the specified array is null |
|
535 |
*/ |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
536 |
@SuppressWarnings("unchecked") |
2 | 537 |
public <T> T[] toArray(T[] a) { |
538 |
// try to use sent-in array |
|
539 |
int k = 0; |
|
540 |
Node<E> p; |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
541 |
for (p = first(); p != null && k < a.length; p = succ(p)) { |
2 | 542 |
E item = p.getItem(); |
543 |
if (item != null) |
|
544 |
a[k++] = (T)item; |
|
545 |
} |
|
546 |
if (p == null) { |
|
547 |
if (k < a.length) |
|
548 |
a[k] = null; |
|
549 |
return a; |
|
550 |
} |
|
551 |
||
552 |
// If won't fit, use ArrayList version |
|
553 |
ArrayList<E> al = new ArrayList<E>(); |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
554 |
for (Node<E> q = first(); q != null; q = succ(q)) { |
2 | 555 |
E item = q.getItem(); |
556 |
if (item != null) |
|
557 |
al.add(item); |
|
558 |
} |
|
559 |
return al.toArray(a); |
|
560 |
} |
|
561 |
||
562 |
/** |
|
563 |
* Returns an iterator over the elements in this queue in proper sequence. |
|
564 |
* The returned iterator is a "weakly consistent" iterator that |
|
565 |
* will never throw {@link ConcurrentModificationException}, |
|
566 |
* and guarantees to traverse elements as they existed upon |
|
567 |
* construction of the iterator, and may (but is not guaranteed to) |
|
568 |
* reflect any modifications subsequent to construction. |
|
569 |
* |
|
570 |
* @return an iterator over the elements in this queue in proper sequence |
|
571 |
*/ |
|
572 |
public Iterator<E> iterator() { |
|
573 |
return new Itr(); |
|
574 |
} |
|
575 |
||
576 |
private class Itr implements Iterator<E> { |
|
577 |
/** |
|
578 |
* Next node to return item for. |
|
579 |
*/ |
|
580 |
private Node<E> nextNode; |
|
581 |
||
582 |
/** |
|
583 |
* nextItem holds on to item fields because once we claim |
|
584 |
* that an element exists in hasNext(), we must return it in |
|
585 |
* the following next() call even if it was in the process of |
|
586 |
* being removed when hasNext() was called. |
|
587 |
*/ |
|
588 |
private E nextItem; |
|
589 |
||
590 |
/** |
|
591 |
* Node of the last returned item, to support remove. |
|
592 |
*/ |
|
593 |
private Node<E> lastRet; |
|
594 |
||
595 |
Itr() { |
|
596 |
advance(); |
|
597 |
} |
|
598 |
||
599 |
/** |
|
600 |
* Moves to next valid node and returns item to return for |
|
601 |
* next(), or null if no such. |
|
602 |
*/ |
|
603 |
private E advance() { |
|
604 |
lastRet = nextNode; |
|
605 |
E x = nextItem; |
|
606 |
||
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
607 |
Node<E> pred, p; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
608 |
if (nextNode == null) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
609 |
p = first(); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
610 |
pred = null; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
611 |
} else { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
612 |
pred = nextNode; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
613 |
p = succ(nextNode); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
614 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
615 |
|
2 | 616 |
for (;;) { |
617 |
if (p == null) { |
|
618 |
nextNode = null; |
|
619 |
nextItem = null; |
|
620 |
return x; |
|
621 |
} |
|
622 |
E item = p.getItem(); |
|
623 |
if (item != null) { |
|
624 |
nextNode = p; |
|
625 |
nextItem = item; |
|
626 |
return x; |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
627 |
} else { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
628 |
// skip over nulls |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
629 |
Node<E> next = succ(p); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
630 |
if (pred != null && next != null) |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
631 |
pred.casNext(p, next); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
632 |
p = next; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
633 |
} |
2 | 634 |
} |
635 |
} |
|
636 |
||
637 |
public boolean hasNext() { |
|
638 |
return nextNode != null; |
|
639 |
} |
|
640 |
||
641 |
public E next() { |
|
642 |
if (nextNode == null) throw new NoSuchElementException(); |
|
643 |
return advance(); |
|
644 |
} |
|
645 |
||
646 |
public void remove() { |
|
647 |
Node<E> l = lastRet; |
|
648 |
if (l == null) throw new IllegalStateException(); |
|
649 |
// rely on a future traversal to relink. |
|
650 |
l.setItem(null); |
|
651 |
lastRet = null; |
|
652 |
} |
|
653 |
} |
|
654 |
||
655 |
/** |
|
656 |
* Save the state to a stream (that is, serialize it). |
|
657 |
* |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
658 |
* @serialData All of the elements (each an {@code E}) in |
2 | 659 |
* the proper order, followed by a null |
660 |
* @param s the stream |
|
661 |
*/ |
|
662 |
private void writeObject(java.io.ObjectOutputStream s) |
|
663 |
throws java.io.IOException { |
|
664 |
||
665 |
// Write out any hidden stuff |
|
666 |
s.defaultWriteObject(); |
|
667 |
||
668 |
// Write out all elements in the proper order. |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
669 |
for (Node<E> p = first(); p != null; p = succ(p)) { |
2 | 670 |
Object item = p.getItem(); |
671 |
if (item != null) |
|
672 |
s.writeObject(item); |
|
673 |
} |
|
674 |
||
675 |
// Use trailing null as sentinel |
|
676 |
s.writeObject(null); |
|
677 |
} |
|
678 |
||
679 |
/** |
|
680 |
* Reconstitute the Queue instance from a stream (that is, |
|
681 |
* deserialize it). |
|
682 |
* @param s the stream |
|
683 |
*/ |
|
684 |
private void readObject(java.io.ObjectInputStream s) |
|
685 |
throws java.io.IOException, ClassNotFoundException { |
|
686 |
// Read in capacity, and any hidden stuff |
|
687 |
s.defaultReadObject(); |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
688 |
head = new Node<E>(null); |
2 | 689 |
tail = head; |
690 |
// Read in all elements and place in queue |
|
691 |
for (;;) { |
|
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
692 |
@SuppressWarnings("unchecked") |
2 | 693 |
E item = (E)s.readObject(); |
694 |
if (item == null) |
|
695 |
break; |
|
696 |
else |
|
697 |
offer(item); |
|
698 |
} |
|
699 |
} |
|
700 |
||
3414
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
701 |
// Unsafe mechanics |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
702 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
703 |
private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe(); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
704 |
private static final long headOffset = |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
705 |
objectFieldOffset(UNSAFE, "head", ConcurrentLinkedQueue.class); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
706 |
private static final long tailOffset = |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
707 |
objectFieldOffset(UNSAFE, "tail", ConcurrentLinkedQueue.class); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
708 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
709 |
private boolean casTail(Node<E> cmp, Node<E> val) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
710 |
return UNSAFE.compareAndSwapObject(this, tailOffset, cmp, val); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
711 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
712 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
713 |
private boolean casHead(Node<E> cmp, Node<E> val) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
714 |
return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
715 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
716 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
717 |
private void lazySetHead(Node<E> val) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
718 |
UNSAFE.putOrderedObject(this, headOffset, val); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
719 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
720 |
|
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
721 |
static long objectFieldOffset(sun.misc.Unsafe UNSAFE, |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
722 |
String field, Class<?> klazz) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
723 |
try { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
724 |
return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
725 |
} catch (NoSuchFieldException e) { |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
726 |
// Convert Exception to corresponding Error |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
727 |
NoSuchFieldError error = new NoSuchFieldError(field); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
728 |
error.initCause(e); |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
729 |
throw error; |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
730 |
} |
cdf768813b4d
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
2
diff
changeset
|
731 |
} |
2 | 732 |
} |