Fix isEmpty() and count()
isEmpty() need not rely on peek(which is intended for consumer use) and instead compare head to tail. count() should stop counting at max int to avoid wrap.
This commit is contained in:
parent
e8cefbf7ba
commit
74d0f0cc6c
1 changed files with 2 additions and 2 deletions
|
|
@ -57,12 +57,12 @@ public abstract class AbstractNodeQueue<T> extends AtomicReference<AbstractNodeQ
|
|||
}
|
||||
|
||||
public final boolean isEmpty() {
|
||||
return peek() == null;
|
||||
return Unsafe.instance.getObjectVolatile(this, tailOffset)) == get();
|
||||
}
|
||||
|
||||
public final int count() {
|
||||
int count = 0;
|
||||
for(Node<T> n = peekNode();n != null; n = n.next())
|
||||
for(Node<T> n = peekNode();n != null && count < Integer.MAX_VALUE; n = n.next())
|
||||
++count;
|
||||
return count;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue