/// <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);
                }
            }
        }
        /// <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 (queue != null)
                    {
                        m_manager.ReturnQueue(queue);
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
 /// <summary>
 /// Creates a new instance of the <see cref="DoubleBufferedQueueProducer{T}"/> class.
 /// </summary>
 /// <param name="manager">The <see cref="DoubleBufferedQueueManager{T}"/> that created this producer.</param>
 /// <param name="queue">The <see cref="DoubleBufferedQueue{T}"/> that this producer will be producing to.</param>
 internal DoubleBufferedQueueProducer(DoubleBufferedQueueManager <T> manager, DoubleBufferedQueue <T> queue)
 {
     m_manager = manager ?? throw new ArgumentNullException(nameof(manager));
     m_queue   = queue ?? throw new ArgumentNullException(nameof(queue));
 }