public final void add(final T value) { final Node<T> n = new Node<T>(value); getAndSet(n).setNext(n); }
/** * 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); }
/** * 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); }
/** * 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); }
public final void add(final T value) { final Node<T> n = new Node<T>(value); getAndSet(n).setNext(n); }
/** * 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); }
/** * Pull one item from the queue, returning it within a queue node. * * Use this method only from the consumer thread! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") public final Node<T> pollNode() { final Node<T> tail = (Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset); Node<T> next = tail.next(); if (next == null && get() != tail) { // if tail != head this is not going to change until producer makes progress // we can avoid reading the head and just spin on next until it shows up do { next = tail.next(); } while (next == null); } if (next == null) return null; else { tail.value = next.value; next.value = null; Unsafe.instance.putOrderedObject(this, tailOffset, next); tail.setNext(null); return tail; } }
/** * Pull one item from the queue, returning it within a queue node. * * Use this method only from the consumer thread! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") public final Node<T> pollNode() { final Node<T> tail = (Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset); Node<T> next = tail.next(); if (next == null && get() != tail) { // if tail != head this is not going to change until producer makes progress // we can avoid reading the head and just spin on next until it shows up do { next = tail.next(); } while (next == null); } if (next == null) return null; else { tail.value = next.value; next.value = null; Unsafe.instance.putOrderedObject(this, tailOffset, next); tail.setNext(null); return tail; } }
/** * Pull one item from the queue, returning it within a queue node. * * Use this method only from the consumer thread! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") public final Node<T> pollNode() { final Node<T> tail = (Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset); Node<T> next = tail.next(); if (next == null && get() != tail) { // if tail != head this is not going to change until producer makes progress // we can avoid reading the head and just spin on next until it shows up do { next = tail.next(); } while (next == null); } if (next == null) return null; else { tail.value = next.value; next.value = null; Unsafe.instance.putOrderedObject(this, tailOffset, next); tail.setNext(null); return tail; } }
/** * Pull one item from the queue, returning it within a queue node. * * Use this method only from the consumer thread! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") public final Node<T> pollNode() { final Node<T> tail = (Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset); Node<T> next = tail.next(); if (next == null && get() != tail) { // if tail != head this is not going to change until producer makes progress // we can avoid reading the head and just spin on next until it shows up do { next = tail.next(); } while (next == null); } if (next == null) return null; else { tail.value = next.value; next.value = null; Unsafe.instance.putOrderedObject(this, tailOffset, next); tail.setNext(null); return tail; } }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }