Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }