Exemplo n.º 1
0
        public T Pop()
        {
            if (Count == 0)
            {
                throw new InvalidOperationException();
            }

            if (_tail.Count == 0)
            {
                var prev = _tail.Prev;

                _tail.Prev = null;

                var releaseNode = _tail;

                Array.Clear(releaseNode.Array, 0, releaseNode.Array.Length);

                _nodePool.Release(releaseNode);

                _tail = prev;
            }

            Count--;

            return(_tail.Array[--_tail.Count]);
        }
Exemplo n.º 2
0
        public void Release(LinkedListStackNode <T> item)
        {
            if (NodeSize != item.Array.Length)
            {
                throw new InvalidOperationException();
            }

            _stackPool.Push(item);
        }
Exemplo n.º 3
0
        public void PushRef(ref T thread)
        {
            if (_tail == null || _tail.Count == NodeSize)
            {
                var node = _nodePool.Get();

                node.Prev = _tail;
                _tail     = node;
            }

            _tail.Array[_tail.Count++] = thread;

            Count++;
        }