public void Update()
    {
        if (m_bRunTest == false)
        {
            return;
        }

        m_bRunTest = false;

        m_raqTestQueue = new RandomAccessQueue <int>(5);

        //test queue

        //queue some random items
        for (int i = 0; i < m_raqTestQueue.Capacity; i++)
        {
            m_raqTestQueue.Enqueue(i);
        }

        //peek last itme
        Debug.Log("Peak Item " + m_raqTestQueue.PeakDequeue());

        //print out results
        while (m_raqTestQueue.Count > 0)
        {
            Debug.Log("Dequeued Item " + m_raqTestQueue.Dequeue());
        }

        //test random access

        //queue some random items
        for (int i = 0; i < m_raqTestQueue.Capacity; i++)
        {
            m_raqTestQueue.Enqueue(i);
        }

        for (int i = 0; i < m_raqTestQueue.Count; i++)
        {
            Debug.Log("Random Access Item " + m_raqTestQueue[i]);
        }

        //test clear
        m_raqTestQueue.Clear();

        //test queue expansion
        for (int i = 0; i < 20; i++)
        {
            m_raqTestQueue.Enqueue(i);
        }

        for (int i = 0; i < m_raqTestQueue.Count; i++)
        {
            Debug.Log("Random Access Item " + m_raqTestQueue[i]);
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Adds a work item to the queue and potentially start a new thread.
        /// A thread is started if there are no idle threads or if there is already
        /// something on the queue - but in each case, only if the total number of
        /// threads is less than the maximum.
        /// </summary>
        /// <param name="workItem">The actual work item to add to the queue.</param>
        public void AddWorkItem([NotNull] ThreadPoolWorkItem workItem)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException(nameof(workItem));
            }

            bool startNewThread;

            lock (_stateLock)
            {
                lock (_queueLock)
                {
                    if (_queue.Count == 0)
                    {
                        _queue.Enqueue(workItem);
                    }
                    else
                    {
                        // Work out where in the queue the item should go

                        // Common case: it belongs at the end
                        if (_queue[_queue.Count - 1].Priority >= workItem.Priority)
                        {
                            _queue.Enqueue(workItem);
                        }
                        else
                        {
                            // This will find the complement of the correct position, due to the
                            // "interesting" nature of PriorityComparer.
                            int position = _queue.BinarySearch(workItem, PriorityComparer.Instance);
                            _queue.Enqueue(workItem, ~position);
                        }
                    }
                    startNewThread = WorkingThreads + _queue.Count > TotalThreads &&
                                     TotalThreads < MaxThreads;
                    // Always pulse the queueLock, whether there's something waiting or not.
                    // This is easier than trying to work out for sure whether or not it's
                    // worth pulsing, and errs on the side of caution.
                    Monitor.Pulse(_queueLock);
                }
            }

            if (startNewThread)
            {
                StartWorkerThread();
            }
        }
        public void QueuePacketToSend(Packet packet)
        {
            m_iPacketsQueuedToSendCount++;

            ProcessSendingTickStampedPackets(packet);

            m_PacketsInFlight.Enqueue(packet);
        }
Esempio n. 4
0
        public void StronglyTypedClone()
        {
            RandomAccessQueue<object> queue = new RandomAccessQueue<object>();

            object first = new object();
            object second = new object();
            queue.Enqueue(first);
            queue.Enqueue(second);

            RandomAccessQueue<object> clone = queue.Clone();

            Assert.AreEqual(queue.Count, clone.Count);

            Assert.AreSame(first, queue.Dequeue());
            Assert.AreSame(first, clone.Dequeue());
            Assert.AreSame(second, queue.Dequeue());
            Assert.AreSame(second, clone.Dequeue());
            Assert.AreNotSame(queue.SyncRoot, clone.SyncRoot);
        }
Esempio n. 5
0
 /// <summary>
 /// Inserts the node into this cache. If the node is already inside the cache, it is moved to the front.
 /// If theres no place inside the cache for this node, other nodes get removed from the cache (and their point data gets deleted) in order to free up space for this node.
 /// If this node still does not fit inside the cache its points are deleted right away.
 /// </summary>
 /// <param name="node">Node, which has its points in memory right now</param>
 public void Insert(Node node)
 {
     lock (queue) {
         Withdraw(node); //it might be in the queue already but has to be moved to the front
         //Alte Objekte aus Cache entfernen
         while (cachePointCount + node.PointCount > maxPoints && !queue.IsEmpty())
         {
             Node old = queue.Dequeue();
             cachePointCount -= (uint)old.PointCount;
             old.ForgetPoints();
         }
         if (cachePointCount + node.PointCount <= maxPoints)
         {
             //In Cache einfügen
             queue.Enqueue(node);
             cachePointCount += (uint)node.PointCount;
         }
         else
         {
             //Nicht in Cache einfügen -> direkt entfernen
             node.ForgetPoints();
         }
     }
 }
        public void ICloneableClone()
        {
            RandomAccessQueue<object> queue = new RandomAccessQueue<object>();

            object first = new object();
            object second = new object();
            queue.Enqueue(first);
            queue.Enqueue(second);

            ICloneable cloneable = queue;
            RandomAccessQueue<object> clone = (RandomAccessQueue<object>)cloneable.Clone();

            Assert.AreEqual(queue.Count, clone.Count);

            Assert.AreSame(first, queue.Dequeue());
            Assert.AreSame(first, clone.Dequeue());
            Assert.AreSame(second, queue.Dequeue());
            Assert.AreSame(second, clone.Dequeue());
            Assert.AreNotSame(queue.SyncRoot, clone.SyncRoot);
        }