Ejemplo n.º 1
0
        /// <summary>
        /// Remove a Command from the queue
        /// </summary>
        public Command Dequeue(out InputState nState, out string nData)
        {
            lock (_lock)                // Lock for thread safety
            {
                CmdQueueNode tempNode = null;

                if (_head != null)
                {
                    tempNode = _head;
                    _head    = _head.Next;
                }

                if (tempNode != null)
                {
                    nState = tempNode.State;
                    nData  = tempNode.Data;
                    return(tempNode.Cmd);
                }
                else
                {
                    nState = InputState.INVALID;
                    nData  = null;
                    return(Command.None);
                }
            }
        }
Ejemplo n.º 2
0
        // Check the length of the queue
        public int NumNodes()
        {
            int          num      = 0;
            CmdQueueNode tempNode = _head;

            while (tempNode != null)
            {
                num++;
                tempNode = tempNode.Next;
            }

            return(num);
        }
Ejemplo n.º 3
0
        private object _lock = new object();            // Threadsafe lock object

        /// <summary>
        /// Add an Command to the queue
        /// </summary>
        public void Enqueue(Command nCmd, InputState nState, string nData = null)
        {
            lock (_lock)                // Lock for thread safety
            {
                CmdQueueNode newNode = new CmdQueueNode(nCmd, nState, nData);
                if (_head == null)
                {
                    _head = newNode;
                    _tail = newNode;
                }
                else
                {
                    _tail.Next = newNode;
                    _tail      = newNode;
                }
            }
        }
Ejemplo n.º 4
0
 public void Dispose()
 {
     Cmd  = null;
     Data = null;
     Next = null;
 }