public bool TryOrderedDequeue(out EntityUpdate value) { for (int iq = 0; iq < NumberOfQueues; ++iq) { MinHeap <MinHeapItem> curheap = m_heaps[iq]; if (curheap.Count > 0) { MinHeapItem item = curheap.RemoveMin(); m_lookupTable.Remove(item.Value.Entity.LocalId); value = item.Value; return(true); } } value = default(EntityUpdate); if (m_lookupTable.Count == 0 && m_added > 8 * m_capacity) { m_lookupTable = new Dictionary <uint, LookupItem>(m_capacity); m_added = 0; } return(false); }
/// <summary> /// Remove an item from one of the queues. Specifically, it removes the /// oldest item from the next queue in order to provide fair access to /// all of the queues /// </summary> public bool TryDequeue(out EntityUpdate value, out Int32 timeinqueue) { // If there is anything in immediate queues, return it first no // matter what else. Breaks fairness. But very useful. for (int iq = 0; iq < NumberOfImmediateQueues; iq++) { if (m_heaps[iq].Count > 0) { MinHeapItem item = m_heaps[iq].RemoveMin(); m_lookupTable.Remove(item.Value.Entity.LocalId); timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime); value = item.Value; return(true); } } // To get the fair queing, we cycle through each of the // queues when finding an element to dequeue. // We pull (NumberOfQueues - QueueIndex) items from each queue in order // to give lower numbered queues a higher priority and higher percentage // of the bandwidth. MinHeap <MinHeapItem> curheap = m_heaps[m_nextQueue]; // Check for more items to be pulled from the current queue if (m_countFromQueue > 0 && curheap.Count > 0) { --m_countFromQueue; MinHeapItem item = curheap.RemoveMin(); m_lookupTable.Remove(item.Value.Entity.LocalId); timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime); value = item.Value; return(true); } // Find the next non-immediate queue with updates in it for (uint i = NumberOfImmediateQueues; i < NumberOfQueues; ++i) { m_nextQueue++; if (m_nextQueue >= NumberOfQueues) { m_nextQueue = NumberOfImmediateQueues; } curheap = m_heaps[m_nextQueue]; if (curheap.Count == 0) { continue; } m_countFromQueue = m_queueCounts[m_nextQueue]; --m_countFromQueue; MinHeapItem item = curheap.RemoveMin(); m_lookupTable.Remove(item.Value.Entity.LocalId); timeinqueue = Util.EnvironmentTickCountSubtract(item.EntryTime); value = item.Value; return(true); } timeinqueue = 0; value = default(EntityUpdate); if (m_lookupTable.Count == 0 && m_added > 8 * m_capacity) { m_lookupTable = new Dictionary <uint, LookupItem>(m_capacity); m_added = 0; } return(false); }