private static void SplitQueue(UnsafeSPSCQueue *q)
        {
            //Wrap tail back to 0
            for (int i = 0; i < 5; i++)
            {
                UnsafeSPSCQueue.Enqueue(q, 111);
            }

            //First half
            for (int i = 0; i < 5; i++)
            {
                UnsafeSPSCQueue.Enqueue(q, i);
            }

            //Move head by 5
            for (int i = 0; i < 5; i++)
            {
                UnsafeSPSCQueue.Dequeue <int>(q);
            }

            //Second half (head and tail are now both 5)
            for (int i = 5; i < 10; i++)
            {
                UnsafeSPSCQueue.Enqueue(q, i);
            }

            //Circular buffer now "ends" in the middle of the underlying array
        }
        public void DequeueTest()
        {
            var q = UnsafeSPSCQueue.Allocate <int>(10);

            for (int i = 0; i < 10; i++)
            {
                UnsafeSPSCQueue.Enqueue(q, i * i);
            }

            for (int i = 0; i < 10; i++)
            {
                int num = UnsafeSPSCQueue.Dequeue <int>(q);
                Assert.AreEqual(i * i, num);
            }

            UnsafeSPSCQueue.Free(q);
        }
        // Demonstration that this queue is SPSC
        public void ConcurrencyTest()
        {
            var q     = UnsafeSPSCQueue.Allocate <int>(16);
            int count = 10000;

            Thread reader = new Thread(() =>
            {
                for (int i = 0; i < count; i++)
                {
                    Assert.AreEqual(i, UnsafeSPSCQueue.Dequeue <int>(q));
                }
            });

            reader.Start();

            for (int i = 0; i < count; i++)
            {
                UnsafeSPSCQueue.Enqueue(q, i);
            }

            reader.Join();

            UnsafeSPSCQueue.Free(q);
        }
Ejemplo n.º 4
0
 public T Dequeue()
 {
     return(UnsafeSPSCQueue.Dequeue <T>(m_inner));
 }