Пример #1
0
        // Remove a Magazine from the queue
        public Magazine Dequeue()
        {
            lock (_lock)    // Lock for thread safety
            {
                MagQueueNode tempNode = null;

                if (_head != null)
                {
                    _count--;   // Only decrement count if a mag was found to remove
                    tempNode = _head;
                    _head    = _head.Next;
                }

                return(tempNode?.Mag ?? new Magazine(0, 0));  // Return empty mag if nothing found
            }
        }
Пример #2
0
 // Add a Magazine to the queue
 public void Enqueue(Magazine nMag)
 {
     lock (_lock)    // Lock for thread safety
     {
         MagQueueNode newNode = new MagQueueNode(nMag);
         if (_head == null)
         {
             _count = 0; // Reset count, head was null
             _head  = newNode;
             _tail  = newNode;
         }
         else
         {
             _count++;   // Increment
             _tail.Next = newNode;
             _tail      = newNode;
         }
     }
 }
Пример #3
0
 public void Dispose()
 {
     _next = null;
 }