/** * Query the queue whether it is empty right now. * * This method can be used from any thread. * * @return true if queue was empty at some point in the past */ public final boolean isEmpty() { return Unsafe.instance.getObjectVolatile(this, tailOffset) == get(); }
/** * Add an element to the head of the queue, providing the queue node to be used. * * This method can be used from any thread. * * @param n the node containing the element to be added; both must not be null */ public final void addNode(final Node<T> n) { n.setNext(null); getAndSet(n).setNext(n); }
/** * Query the queue tail for the next element without dequeuing it. * * Use this method only from the consumer thread! * * @return element if there was one, or null if there was none */ public final T peek() { final Node<T> n = peekNode(); return (n != null) ? n.value : null; }
protected AbstractNodeQueue() { final Node<T> n = new Node<T>(); _tailDoNotCallMeDirectly = n; set(n); }
/** * Pull one item from the queue’s tail if there is one. * * Use this method only from the consumer thread! * * @return element if there was one, or null if there was none */ public final T poll() { final Node<T> next = pollNode(); if (next == null) return null; else { T value = next.value; next.value = null; return value; } }
/** * Query the queue whether it is empty right now. * * This method can be used from any thread. * * @return true if queue was empty at some point in the past */ public final boolean isEmpty() { return peek() == null; }
protected AbstractNodeQueue() { final Node<T> n = new Node<T>(); _tailDoNotCallMeDirectly = n; set(n); }
/** * Pull one item from the queue’s tail if there is one. * * Use this method only from the consumer thread! * * @return element if there was one, or null if there was none */ public final T poll() { final Node<T> next = pollNode(); if (next == null) return null; else { T value = next.value; next.value = null; return value; } }
/** * Query the queue whether it is empty right now. * * This method can be used from any thread. * * @return true if queue was empty at some point in the past */ public final boolean isEmpty() { return peek() == null; }
/** * Query the queue whether it is empty right now. * * This method can be used from any thread. * * @return true if queue was empty at some point in the past */ public final boolean isEmpty() { return Unsafe.instance.getObjectVolatile(this, tailOffset) == get(); }
/** * Add an element to the head of the queue. * * This method can be used from any thread. * * @param value the element to be added; must not be null */ public final void add(final T value) { final Node<T> n = new Node<T>(value); getAndSet(n).setNext(n); }
/** * Query the queue tail for the next element without dequeuing it. * * Use this method only from the consumer thread! * * @return element if there was one, or null if there was none */ public final T peek() { final Node<T> n = peekNode(); return (n != null) ? n.value : null; }
protected AbstractNodeQueue() { final Node<T> n = new Node<T>(); _tailDoNotCallMeDirectly = n; set(n); }
/** * Pull one item from the queue’s tail if there is one. * * Use this method only from the consumer thread! * * @return element if there was one, or null if there was none */ public final T poll() { final Node<T> next = pollNode(); if (next == null) return null; else { T value = next.value; next.value = null; return value; } }
/** * Query the queue whether it is empty right now. * * This method can be used from any thread. * * @return true if queue was empty at some point in the past */ public final boolean isEmpty() { return peek() == null; }
/** * Query the queue whether it is empty right now. * * This method can be used from any thread. * * @return true if queue was empty at some point in the past */ public final boolean isEmpty() { return Unsafe.instance.getObjectVolatile(this, tailOffset) == get(); }
/** * Add an element to the head of the queue, providing the queue node to be used. * * This method can be used from any thread. * * @param n the node containing the element to be added; both must not be null */ public final void addNode(final Node<T> n) { n.setNext(null); getAndSet(n).setNext(n); }
/** * Query the queue tail for the next element without dequeuing it. * * Use this method only from the consumer thread! * * @return element if there was one, or null if there was none */ public final T peek() { final Node<T> n = peekNode(); return (n != null) ? n.value : null; }
protected AbstractNodeQueue() { final Node<T> n = new Node<T>(); _tailDoNotCallMeDirectly = n; set(n); }
/** * Pull one item from the queue’s tail if there is one. * * Use this method only from the consumer thread! * * @return element if there was one, or null if there was none */ public final T poll() { final Node<T> next = pollNode(); if (next == null) return null; else { T value = next.value; next.value = null; return value; } }