Esempio n. 1
0
        protected T RelaxedPeek()
        {
            LinkedQueueNode <T> currConsumerNode = this.ConsumerNode; // don't load twice, it's alright
            LinkedQueueNode <T> nextNode         = currConsumerNode.LvNext();

            return(nextNode?.LpValue());
        }
Esempio n. 2
0
        protected T RelaxedPoll()
        {
            LinkedQueueNode <T> currConsumerNode = this.LpConsumerNode(); // don't load twice, it's alright
            LinkedQueueNode <T> nextNode         = currConsumerNode.LvNext();

            return(nextNode != null
                ? this.GetSingleConsumerNodeValue(currConsumerNode, nextNode)
                : null);
        }
Esempio n. 3
0
        public override bool Offer(T e)
        {
            Contract.Requires(e != null);

            var nextNode = new LinkedQueueNode <T>(e);
            LinkedQueueNode <T> producerNode = this.LpProducerNode();

            producerNode.SoNext(nextNode);
            this.SpProducerNode(nextNode);

            return(true);
        }
Esempio n. 4
0
        protected T GetSingleConsumerNodeValue(LinkedQueueNode <T> currConsumerNode, LinkedQueueNode <T> nextNode)
        {
            // we have to null out the value because we are going to hang on to the node
            T nextValue = nextNode.GetAndNullValue();

            // Fix up the next ref of currConsumerNode to prevent promoted nodes from keep new ones alive.
            // We use a reference to self instead of null because null is already a meaningful value (the next of
            // producer node is null).
            currConsumerNode.SoNext(currConsumerNode);
            this.SpConsumerNode(nextNode);

            // currConsumerNode is now no longer referenced and can be collected
            return(nextValue);
        }
Esempio n. 5
0
        public override bool Offer(T e)
        {
            if (e is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.e);
            }

            var nextNode = new LinkedQueueNode <T>(e);
            LinkedQueueNode <T> producerNode = this.LpProducerNode();

            producerNode.SoNext(nextNode);
            this.SpProducerNode(nextNode);

            return(true);
        }
Esempio n. 6
0
 public void SoNext(LinkedQueueNode <T> n) => Volatile.Write(ref this.next, n);
Esempio n. 7
0
 protected void SpProducerNode(LinkedQueueNode <T> node) => this.ProducerNode = node;
Esempio n. 8
0
 protected void SpConsumerNode(LinkedQueueNode <T> node) => this.ConsumerNode = node;