public AbstractMpscLinkedQueue() { producerNode = new AtomicReference<LinkedQueueNode<T>>(); consumerNode = new AtomicReference<LinkedQueueNode<T>>(); LinkedQueueNode<T> node = new LinkedQueueNode<T>(); spConsumerNode(node); xchgProducerNode(node);// this ensures correct construction: StoreLoad }
public final boolean offer(final T e) { if (null == e) { throw new NullPointerException("Null is not a valid element"); } final LinkedQueueNode<T> nextNode = new LinkedQueueNode<T>(e); final LinkedQueueNode<T> prevProducerNode = xchgProducerNode(nextNode); // Should a producer thread get interrupted here the chain WILL be broken until that thread is resumed // and completes the store in prev.next. prevProducerNode.soNext(nextNode); // StoreStore return true; }
@Nullable public final T poll() { LinkedQueueNode<T> currConsumerNode = lpConsumerNode(); // don't load twice, it's alright LinkedQueueNode<T> nextNode = currConsumerNode.lvNext(); if (nextNode != null) { // we have to null out the value because we are going to hang on to the node final T nextValue = nextNode.getAndNullValue(); spConsumerNode(nextNode); return nextValue; } else if (currConsumerNode != lvProducerNode()) { // spin, we are no longer wait free while ((nextNode = currConsumerNode.lvNext()) == null) { } // NOPMD // got the next node... // we have to null out the value because we are going to hang on to the node final T nextValue = nextNode.getAndNullValue(); spConsumerNode(nextNode); return nextValue; } return null; }
@Nullable public final T poll() { LinkedQueueNode<T> currConsumerNode = lpConsumerNode(); // don't load twice, it's alright LinkedQueueNode<T> nextNode = currConsumerNode.lvNext(); if (nextNode != null) { // we have to null out the value because we are going to hang on to the node final T nextValue = nextNode.getAndNullValue(); spConsumerNode(nextNode); return nextValue; } else if (currConsumerNode != lvProducerNode()) { // spin, we are no longer wait free while ((nextNode = currConsumerNode.lvNext()) == null) { } // NOPMD // got the next node... // we have to null out the value because we are going to hang on to the node final T nextValue = nextNode.getAndNullValue(); spConsumerNode(nextNode); return nextValue; } return null; }
@Nullable public final T poll() { LinkedQueueNode<T> currConsumerNode = lpConsumerNode(); // don't load twice, it's alright LinkedQueueNode<T> nextNode = currConsumerNode.lvNext(); if (nextNode != null) { // we have to null out the value because we are going to hang on to the node final T nextValue = nextNode.getAndNullValue(); spConsumerNode(nextNode); return nextValue; } else if (currConsumerNode != lvProducerNode()) { // spin, we are no longer wait free while ((nextNode = currConsumerNode.lvNext()) == null) { } // NOPMD // got the next node... // we have to null out the value because we are going to hang on to the node final T nextValue = nextNode.getAndNullValue(); spConsumerNode(nextNode); return nextValue; } return null; }
public void soNext(LinkedQueueNode<E> n) { lazySet(n); }
public void soNext(LinkedQueueNode<E> n) { lazySet(n); }
public void soNext(LinkedQueueNode<E> n) { lazySet(n); }
LinkedQueueNode(E val) { spValue(val); } /**
public LinkedQueueNode<E> lvNext() { return get(); } }
LinkedQueueNode(E val) { spValue(val); } /**
LinkedQueueNode(E val) { spValue(val); } /**
public LinkedQueueNode<E> lvNext() { return get(); } }
public LinkedQueueNode<E> lvNext() { return get(); } }
public final boolean offer(final T e) { if (null == e) { throw new NullPointerException("Null is not a valid element"); } final LinkedQueueNode<T> nextNode = new LinkedQueueNode<T>(e); final LinkedQueueNode<T> prevProducerNode = xchgProducerNode(nextNode); // Should a producer thread get interrupted here the chain WILL be broken until that thread is resumed // and completes the store in prev.next. prevProducerNode.soNext(nextNode); // StoreStore return true; }
public final boolean offer(final T e) { if (null == e) { throw new NullPointerException("Null is not a valid element"); } final LinkedQueueNode<T> nextNode = new LinkedQueueNode<T>(e); final LinkedQueueNode<T> prevProducerNode = xchgProducerNode(nextNode); // Should a producer thread get interrupted here the chain WILL be broken until that thread is resumed // and completes the store in prev.next. prevProducerNode.soNext(nextNode); // StoreStore return true; }
public AbstractMpscLinkedQueue() { producerNode = new AtomicReference<LinkedQueueNode<T>>(); consumerNode = new AtomicReference<LinkedQueueNode<T>>(); LinkedQueueNode<T> node = new LinkedQueueNode<T>(); spConsumerNode(node); xchgProducerNode(node);// this ensures correct construction: StoreLoad }
public AbstractMpscLinkedQueue() { producerNode = new AtomicReference<LinkedQueueNode<T>>(); consumerNode = new AtomicReference<LinkedQueueNode<T>>(); LinkedQueueNode<T> node = new LinkedQueueNode<T>(); spConsumerNode(node); xchgProducerNode(node);// this ensures correct construction: StoreLoad }