/// <summary> /// Retrieves the next work item from the queue, pausing for at most /// the specified amount of time. /// </summary> /// <param name="waitPeriod"> /// The maximum amount of time to wait for a work item to arrive, in ms. /// </param> /// <returns> /// The next work item, or null if there aren't any after waiting /// for the specified period. /// </returns> private ThreadPoolWorkItem GetNextWorkItem(int waitPeriod) { lock (_queueLock) { if (_queue.Count != 0) { return(_queue.Dequeue()); } Monitor.Wait(_queueLock, waitPeriod); if (_queue.Count != 0) { return(_queue.Dequeue()); } return(null); } }
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); }
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]); } }
private void SendPackets() { //check if there is anything to send if (m_PacketsInFlight.Count == 0) { return; } //calculate the number of packets that dont need to be sent int iPacketsToDrop = m_PacketsInFlight.Count - (m_iPacketsQueuedToSendCount - m_iLastAckPacketNumberSent); if (iPacketsToDrop >= m_PacketsInFlight.Count) { m_PacketsInFlight.Clear(); return; } //dequeue all the old packets that have already been acknowledged for (int i = 0; i < iPacketsToDrop; i++) { m_PacketsInFlight.Dequeue(); } if (m_PacketsInFlight.Count == 0) { return; } //create packet wrapper PacketWrapper pkwPacketWrappepr = new PacketWrapper(m_iTotalPacketsReceived, m_iPacketsQueuedToSendCount - m_PacketsInFlight.Count, m_PacketsInFlight.Count); //add as many packets as possible without hitting the max send data limit for (int i = 0; i < m_PacketsInFlight.Count; i++) { pkwPacketWrappepr.AddDataPacket(m_PacketsInFlight[i]); } //send packet through coms if (m_icsConnectionSim != null) { m_icsConnectionSim.SendPacket(pkwPacketWrappepr, m_conConnectionTarget); } }
/// <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); }