int sourceSize = this.sourceQueue.size();
if (this.peekCount != 0) {
// There were readings, check for the conflicts.
if (globalState.globalPollCount != this.globalPollCount) {
// We were reading from the head, and it is different the global state.
throw new ConflictException("Queue's head was updated");
}
boolean pastSource = this.peekCount > sourceSize;
if (pastSource && globalState.sourceQueue != this.sourceQueue) {
// We read past the source queue length, into the tail, while the global state had been extended with
// more elements on the tail. (difference of references in this case means exactly that)
throw new ConflictException("Reading past source queue with tail concurrently updated");
}
}
if (this.pollCount == 0 && tail.isEmpty()) {
return globalState;