public bool Dequeue(out T item) { item = default(T); SingleLinkNode <T> oldHead = null; bool haveAdvancedHead = false; while (!haveAdvancedHead) { oldHead = head; SingleLinkNode <T> oldTail = tail; SingleLinkNode <T> oldHeadNext = oldHead.Next; if (oldHead == head) { if (oldHead == oldTail) { if (oldHeadNext == null) { return(false); } CAS <SingleLinkNode <T> >(ref tail, oldTail, oldHeadNext); } else { item = oldHeadNext.Item; haveAdvancedHead = CAS <SingleLinkNode <T> >(ref head, oldHead, oldHeadNext); } } } return(true); }
public void Enqueue(T item) { SingleLinkNode <T> oldTail = null; SingleLinkNode <T> oldTailNext; SingleLinkNode <T> newNode = new SingleLinkNode <T>(); newNode.Item = item; bool newNodeWasAdded = false; while (!newNodeWasAdded) { oldTail = tail; oldTailNext = oldTail.Next; if (tail == oldTail) { if (oldTailNext == null) { newNodeWasAdded = CAS <SingleLinkNode <T> >(ref tail.Next, null, newNode); } else { CAS <SingleLinkNode <T> >(ref tail, oldTail, oldTailNext); } } } CAS <SingleLinkNode <T> >(ref tail, oldTail, newNode); }
public bool MoveNext() { if (current.Next == null) { return(false); } current = current.Next; return(true); }
public LockFreeQueue() { head = new SingleLinkNode <T>(); tail = head; }
public void Reset() { current = queue.head; }
public LockFreeQueueEnumerator(LockFreeQueue <U> queue) { this.queue = queue; this.current = queue.head; }