void ThinkDataInPhase() { if (REQ && ACK) { REQ = false; } else if (!REQ && !ACK) { if (DataIn.Count > 0) { DataBits = DataIn.Dequeue(); REQ = true; } else { // data transfer is finished pce.IntDataTransferReady = false; if (DataTransferWasDone) { DataTransferInProgress = false; DataTransferWasDone = false; pce.IntDataTransferComplete = true; } SetStatusMessage(STATUS_GOOD, 0); } } }
public void Add(double time) { if (queue.Count == Capacity) { queue.Dequeue(); } queue.EnqueueUnsafely(time); }
public static void TestQueueResizing(IUnmanagedMemoryPool pool) { Random random = new Random(5); var queue = new QuickQueue <int>(4, pool); Queue <int> controlQueue = new Queue <int>(); for (int iterationIndex = 0; iterationIndex < 1000000; ++iterationIndex) { if (random.NextDouble() < 0.7) { queue.Enqueue(iterationIndex, pool); controlQueue.Enqueue(iterationIndex); } if (random.NextDouble() < 0.2) { queue.Dequeue(); controlQueue.Dequeue(); } if (iterationIndex % 1000 == 0) { queue.EnsureCapacity(queue.Count * 3, pool); } else if (iterationIndex % 7777 == 0) { queue.Compact(pool); } } Debug.Assert(queue.Count == controlQueue.Count, "e"); while (queue.Count > 0) { var a = queue.Dequeue(); var b = controlQueue.Dequeue(); Debug.Assert(a == b); Debug.Assert(queue.Count == controlQueue.Count); } queue.Dispose(pool); }
public static void TestQueueResizing() { Random random = new Random(5); UnsafeBufferPool <int> pool = new UnsafeBufferPool <int>(); QuickQueue <int> queue = new QuickQueue <int>(pool, 2); Queue <int> controlQueue = new Queue <int>(); for (int iterationIndex = 0; iterationIndex < 1000000; ++iterationIndex) { if (random.NextDouble() < 0.7) { queue.Enqueue(iterationIndex); controlQueue.Enqueue(iterationIndex); } if (random.NextDouble() < 0.2) { queue.Dequeue(); controlQueue.Dequeue(); } if (iterationIndex % 1000 == 0) { queue.EnsureCapacity(queue.Count * 3); } else if (iterationIndex % 7777 == 0) { queue.Compact(); } } Assert.IsTrue(queue.Count == controlQueue.Count); while (queue.Count > 0) { var a = queue.Dequeue(); var b = controlQueue.Dequeue(); Assert.IsTrue(a == b); Assert.IsTrue(queue.Count == controlQueue.Count); } }
public static void TestQueueResizing() { Random random = new Random(5); UnsafeBufferPool<int> pool = new UnsafeBufferPool<int>(); QuickQueue<int> queue = new QuickQueue<int>(pool, 2); Queue<int> controlQueue = new Queue<int>(); for (int iterationIndex = 0; iterationIndex < 1000000; ++iterationIndex) { if (random.NextDouble() < 0.7) { queue.Enqueue(iterationIndex); controlQueue.Enqueue(iterationIndex); } if (random.NextDouble() < 0.2) { queue.Dequeue(); controlQueue.Dequeue(); } if (iterationIndex % 1000 == 0) { queue.EnsureCapacity(queue.Count * 3); } else if (iterationIndex % 7777 == 0) { queue.Compact(); } } Assert.IsTrue(queue.Count == controlQueue.Count); while (queue.Count > 0) { var a = queue.Dequeue(); var b = controlQueue.Dequeue(); Assert.IsTrue(a == b); Assert.IsTrue(queue.Count == controlQueue.Count); } }