160 |
|
} |
161 |
|
|
162 |
|
/** |
163 |
< |
* Creates a node and links it at end of queue. |
163 |
> |
* Links node at end of queue. |
164 |
|
* |
165 |
< |
* @param x the item |
165 |
> |
* @param node the node |
166 |
|
*/ |
167 |
< |
private void enqueue(E x) { |
167 |
> |
private void enqueue(Node<E> node) { |
168 |
|
// assert putLock.isHeldByCurrentThread(); |
169 |
|
// assert last.next == null; |
170 |
< |
last = last.next = new Node<E>(x); |
170 |
> |
last = last.next = node; |
171 |
|
} |
172 |
|
|
173 |
|
/** |
253 |
|
throw new NullPointerException(); |
254 |
|
if (n == capacity) |
255 |
|
throw new IllegalStateException("Queue full"); |
256 |
< |
enqueue(e); |
256 |
> |
enqueue(new Node<E>(e)); |
257 |
|
++n; |
258 |
|
} |
259 |
|
count.set(n); |
303 |
|
// Note: convention in all put/take/etc is to preset local var |
304 |
|
// holding count negative to indicate failure unless set. |
305 |
|
int c = -1; |
306 |
+ |
Node<E> node = new Node(e); |
307 |
|
final ReentrantLock putLock = this.putLock; |
308 |
|
final AtomicInteger count = this.count; |
309 |
|
putLock.lockInterruptibly(); |
319 |
|
while (count.get() == capacity) { |
320 |
|
notFull.await(); |
321 |
|
} |
322 |
< |
enqueue(e); |
322 |
> |
enqueue(node); |
323 |
|
c = count.getAndIncrement(); |
324 |
|
if (c + 1 < capacity) |
325 |
|
notFull.signal(); |
354 |
|
return false; |
355 |
|
nanos = notFull.awaitNanos(nanos); |
356 |
|
} |
357 |
< |
enqueue(e); |
357 |
> |
enqueue(new Node<E>(e)); |
358 |
|
c = count.getAndIncrement(); |
359 |
|
if (c + 1 < capacity) |
360 |
|
notFull.signal(); |
383 |
|
if (count.get() == capacity) |
384 |
|
return false; |
385 |
|
int c = -1; |
386 |
+ |
Node<E> node = new Node(e); |
387 |
|
final ReentrantLock putLock = this.putLock; |
388 |
|
putLock.lock(); |
389 |
|
try { |
390 |
|
if (count.get() < capacity) { |
391 |
< |
enqueue(e); |
391 |
> |
enqueue(node); |
392 |
|
c = count.getAndIncrement(); |
393 |
|
if (c + 1 < capacity) |
394 |
|
notFull.signal(); |