/** * Removes the first element of this queue if any * @return the `Node` of the first element of the queue, null if empty */ public final Node<T> pollNode() { for(;;) { final Node<T> deq = getDeq(); final Node<T> next = deq.next(); if (next != null) { if (casDeq(deq, next)) { deq.value = next.value; deq.setNext(null); next.value = null; return deq; } // else we retry (concurrent consumers) } else if (getEnq() == deq) return null; // If we got a null and head meets tail, we are empty } }
/** * Removes the first element of this queue if any * @return the `Node` of the first element of the queue, null if empty */ public final Node<T> pollNode() { for(;;) { final Node<T> deq = getDeq(); final Node<T> next = deq.next(); if (next != null) { if (casDeq(deq, next)) { deq.value = next.value; deq.setNext(null); next.value = null; return deq; } // else we retry (concurrent consumers) } else if (getEnq() == deq) return null; // If we got a null and head meets tail, we are empty } }
/** * Removes the first element of this queue if any * @return the `Node` of the first element of the queue, null if empty */ public final Node<T> pollNode() { for(;;) { final Node<T> deq = getDeq(); final Node<T> next = deq.next(); if (next != null) { if (casDeq(deq, next)) { deq.value = next.value; deq.setNext(null); next.value = null; return deq; } // else we retry (concurrent consumers) } else if (getEnq() == deq) return null; // If we got a null and head meets tail, we are empty } }
@SuppressWarnings("unchecked") protected final Node<T> peekNode() { for(;;) { final Node<T> deq = getDeq(); final Node<T> next = deq.next(); if (next != null || getEnq() == deq) return next; } }
@SuppressWarnings("unchecked") protected final Node<T> peekNode() { for(;;) { final Node<T> deq = getDeq(); final Node<T> next = deq.next(); if (next != null || getEnq() == deq) return next; } }
@SuppressWarnings("unchecked") protected final Node<T> peekNode() { for(;;) { final Node<T> deq = getDeq(); final Node<T> next = deq.next(); if (next != null || getEnq() == deq) return next; } }