Exemple #1
0
        public void Enqueue(T[] items, int offset, int length)
        {
            items.ValidateParameters(offset, length);
            while (true)
            {
                //If the header is empty. Get a new one.
                if (m_currentHead == null || !m_currentHead.CanEnqueue)
                {
                    m_currentHead = GetNode();
                    m_currentHead.Reset();
                    Thread.MemoryBarrier();
                    m_blocks.Enqueue(m_currentHead);
                    m_enqueueCount++;
                }

                //If the remainder will fit, queue it all.
                int enqueueLength = m_currentHead.AvailableEnqueueLength;
                if (length <= enqueueLength)
                {
                    m_currentHead.Enqueue(items, offset, length);
                    m_enqueueCount += length;
                    return;
                }

                //Some will not fit. Enqueue what will fit, then repeat.
                m_currentHead.Enqueue(items, offset, enqueueLength);
                m_enqueueCount += enqueueLength;
                offset         += enqueueLength;
                length         -= enqueueLength;
            }
        }
Exemple #2
0
 void EnqueueSlower(T item)
 {
     if (m_currentHead == null || !m_currentHead.CanEnqueue)
     {
         m_currentHead = GetNode();
         m_currentHead.Reset();
         Thread.MemoryBarrier();
         m_blocks.Enqueue(m_currentHead);
         m_enqueueCount++;
     }
     m_currentHead.Enqueue(item);
 }