Пример #1
0
        /// <summary>
        /// En-queue data.
        /// </summary>
        /// <param name="data">
        /// Specifies the data to be en-queued.
        /// </param>
        /// <exception cref="System.Threading.ThreadInterruptedException">
        /// Thrown when en-queueing is interrupted.
        /// </exception>
        public void Enqueue(T data)
        {
            SinglyLinkedNode <T> newNode = new SinglyLinkedNode <T>(data);

            // Lock the put lock. May throw TIE here
            lock (_putLock)
            {
                lock (_tailNode)
                {
                    _tailNode.Next = newNode;
                    _tailNode      = newNode;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// De-queue.
        /// </summary>
        /// <returns>
        /// Returns the top element in the queue.
        /// </returns>
        /// <exception cref="System.Threading.ThreadInterruptedException">
        /// Thrown when de-queueing is interrupted.
        /// </exception>
        public T Dequeue()
        {
            // Lock with the take lock. May throw TIE here
            lock (_takeLock)
            {
                lock (_headNode)
                {
                    T data = default(T);
                    SinglyLinkedNode <T> firstNode = _headNode.Next;

                    if (firstNode != null)
                    {
                        data           = firstNode.Data;
                        firstNode.Data = default(T);
                        _headNode      = firstNode;
                    }
                    return(data);
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of Queue.
 /// </summary>
 public Queue()
 {
     _tailNode = _headNode;
 }