Esempio n. 1
0
        public SList()
        {
            var tail = new SListNode();

            tail.Next = tail;
            _headNode = tail;
        }
Esempio n. 2
0
        private void Insert(SListNode node)
        {
            bool success;

            do
            {
                node.Next = _headNode;
                success   = Interlocked.CompareExchange(ref _headNode, node, node.Next) == node.Next;
            } while (!success);
        }
Esempio n. 3
0
        private SListNode Dequeue()
        {
            do
            {
                SListNode slot     = _headNode;
                var       previous = Interlocked.CompareExchange(ref _headNode, slot.Next, slot);
                if (previous == slot) // Successful compare exchange
                {
                    if (slot.Next == slot)
                    {
                        // reached the end of the list
                        return(null);
                    }

                    return(slot);
                }
            } while (true);
        }