Beispiel #1
0
        public TShell Spawn()
        {
            lock (this)
            {
                while (m_Alives1.Count > 0)
                {
                    var resource = m_Alives1.Dequeue();
                    if (resource.Shell.IsAlive == false)
                    {
                        m_Deads.Enqueue(resource.Fillings);
                    }
                    else
                    {
                        m_Alives2.Enqueue(resource);
                    }
                }

                var alive = m_Alives1;
                m_Alives1 = m_Alives2;
                m_Alives2 = alive;

                if (m_Deads.Count > 0)
                {
                    var    fillings = m_Deads.Dequeue();
                    TShell shell;
                    m_Pool.Reset(out shell, fillings);
                    m_Alives1.Enqueue(new Resource(shell, fillings));
                    return(shell);
                }
                else
                {
                    TShell  shell;
                    TObject fillings;
                    m_Pool.New(out shell, out fillings);
                    m_Alives1.Enqueue(new Resource(shell, fillings));
                    return(shell);
                }
            }
        }