Esempio n. 1
0
        /// <summary>
        /// Returns a queue to the <see cref="DoubleBufferedQueueManager{T}"/>
        /// so that it can be removed from the list of queues to be consumed.
        /// </summary>
        /// <param name="queue">The queue to be returned.</param>
        internal void ReturnQueue(DoubleBufferedQueue <T> queue)
        {
            int last;
            int index;

            lock (m_queuesLock)
            {
                index = m_queues.IndexOf(queue);

                if (index >= 0)
                {
                    last            = m_queues.Count - 1;
                    m_queues[index] = m_queues[last];
                    m_queues.RemoveAt(last);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="DoubleBufferedQueueProducer{T}"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    DoubleBufferedQueue <T> queue = Interlocked.Exchange(ref m_queue, null);

                    if ((object)queue != null)
                    {
                        m_manager.ReturnQueue(queue);
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }