Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,21 @@ public boolean offer(final T e) {
public T poll() {
LinkedQueueNode<T> currConsumerNode = lpConsumerNode(); // don't load twice, it's alright
LinkedQueueNode<T> nextNode = currConsumerNode.lvNext();
if (nextNode != null) {
// we have to null out the value because we are going to hang on to the node
final T nextValue = nextNode.getAndNullValue();
spConsumerNode(nextNode);
return nextValue;
final T nextValue;
if (nextNode == null && currConsumerNode == lvProducerNode()) {
return null;
}
else if (currConsumerNode != lvProducerNode()) {
if (nextNode == null) {
// spin, we are no longer wait free
while ((nextNode = currConsumerNode.lvNext()) == null) { } // NOPMD
// got the next node...

// we have to null out the value because we are going to hang on to the node
final T nextValue = nextNode.getAndNullValue();
spConsumerNode(nextNode);
return nextValue;
}
return null;
// we have to null out the value because we are going to hang on to the node
nextValue = nextNode.getAndNullValue();
spConsumerNode(nextNode);
// unlink previous consumer to help gc
currConsumerNode.soNext(null);
return nextValue;
}

@Override
Expand Down