/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * Query the queue tail for the next element without dequeuing it. * * Use this method only from the consumer thread! * * !!! There is a copy of this code in pollNode() !!! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") protected final Node<T> peekNode() { for(;;) { final Node<T> tail = ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset)); final Node<T> next = tail.next(); if (next != null || get() == tail) return next; } }
/** * This method returns an upper bound on the queue size at the time it * starts executing. It may spuriously return smaller values (including * zero) if the consumer pulls items out concurrently. * * This method can be used from any thread. * * @return an upper bound on queue length at some time in the past */ @SuppressWarnings("unchecked") public final int count() { int count = 0; final Node<T> head = get(); for(Node<T> n = ((Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset)).next(); n != null && count < Integer.MAX_VALUE; n = n.next()) { ++count; // only iterate up to the point where head was when starting: this is a moving queue! if (n == head) break; } return count; }
/** * This method returns an upper bound on the queue size at the time it * starts executing. It may spuriously return smaller values (including * zero) if the consumer pulls items out concurrently. * * This method can be used from any thread. * * @return an upper bound on queue length at some time in the past */ @SuppressWarnings("unchecked") public final int count() { int count = 0; final Node<T> head = get(); for(Node<T> n = ((Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset)).next(); n != null && count < Integer.MAX_VALUE; n = n.next()) { ++count; // only iterate up to the point where head was when starting: this is a moving queue! if (n == head) break; } return count; }
/** * This method returns an upper bound on the queue size at the time it * starts executing. It may spuriously return smaller values (including * zero) if the consumer pulls items out concurrently. * * This method can be used from any thread. * * @return an upper bound on queue length at some time in the past */ @SuppressWarnings("unchecked") public final int count() { int count = 0; final Node<T> head = get(); for(Node<T> n = ((Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset)).next(); n != null && count < Integer.MAX_VALUE; n = n.next()) { ++count; // only iterate up to the point where head was when starting: this is a moving queue! if (n == head) break; } return count; }
/** * Query the queue tail for the next element without dequeuing it. * * Use this method only from the consumer thread! * * !!! There is a copy of this code in pollNode() !!! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") protected final Node<T> peekNode() { 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); } return next; }
/** * Query the queue tail for the next element without dequeuing it. * * Use this method only from the consumer thread! * * !!! There is a copy of this code in pollNode() !!! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") protected final Node<T> peekNode() { 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); } return next; }
/** * This method returns an upper bound on the queue size at the time it * starts executing. It may spuriously return smaller values (including * zero) if the consumer pulls items out concurrently. * * This method can be used from any thread. * * @return an upper bound on queue length at some time in the past */ @SuppressWarnings("unchecked") public final int count() { int count = 0; final Node<T> head = get(); for(Node<T> n = ((Node<T>) Unsafe.instance.getObjectVolatile(this, tailOffset)).next(); n != null && count < Integer.MAX_VALUE; n = n.next()) { ++count; // only iterate up to the point where head was when starting: this is a moving queue! if (n == head) break; } return count; }
/** * Query the queue tail for the next element without dequeuing it. * * Use this method only from the consumer thread! * * !!! There is a copy of this code in pollNode() !!! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") protected final Node<T> peekNode() { 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); } return next; }
/** * 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; } }
@SuppressWarnings("unchecked") protected final Node<T> peekNode() { for(;;) { final Node<T> tail = ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset)); final Node<T> next = tail.next(); if (next != null || get() == tail) return next; } }
@SuppressWarnings("unchecked") protected final Node<T> peekNode() { for(;;) { final Node<T> tail = ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset)); final Node<T> next = tail.next(); if (next != null || get() == tail) return next; } }
/** * Query the queue tail for the next element without dequeuing it. * * Use this method only from the consumer thread! * * !!! There is a copy of this code in pollNode() !!! * * @return queue node with element inside if there was one, or null if there was none */ @SuppressWarnings("unchecked") protected final Node<T> peekNode() { for(;;) { final Node<T> tail = ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset)); final Node<T> next = tail.next(); if (next != null || get() == tail) return next; } }
@SuppressWarnings("unchecked") public final Node<T> pollNode() { Node<T> tail; Node<T> next; for(;;) { tail = ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset)); next = tail.next(); if (next != null || get() == tail) break; } if (next == null) return null; else { tail.value = next.value; next.value = null; Unsafe.instance.putOrderedObject(this, tailOffset, next); return tail; } }
@SuppressWarnings("unchecked") public final Node<T> pollNode() { Node<T> tail; Node<T> next; for(;;) { tail = ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset)); next = tail.next(); if (next != null || get() == tail) break; } if (next == null) return null; else { tail.value = next.value; next.value = null; Unsafe.instance.putOrderedObject(this, tailOffset, next); return tail; } }