Exemplo n.º 1
0
        /// <summary>
        ///     获取对象
        /// </summary>
        /// <returns></returns>
        public T GetObject()
        {
            if (ObjectStack.Count == 0)
            {
                var p = GetT();
                if (GetObjectRunTime != null)
                {
                    p = GetObjectRunTime(p, this);
                }
                I1++;
                return(p);
            }
            else
            {
#if USEConcurrent
                T p;

                if (ObjectStack.TryPop(out p))
                {
                    if (GetObjectRunTime != null)
                    {
                        p = GetObjectRunTime(p, this);
                    }

                    I2++;

                    return(p);
                }
                p = GetT();

                if (GetObjectRunTime != null)
                {
                    p = GetObjectRunTime(p, this);
                }

                return(p);
#else
                T p;

#if  lockStack == true
                lock (lockStack)
                {
#endif
                if (ObjectStack.Count > 0)
                {
                    i2++;

                    p = ObjectStack.Pop();

                    if (p == null)
                    {
                        p = GetT();
                    }

                    if (GetObjectRunTime != null)
                    {
                        p = GetObjectRunTime(p, this);
                    }

                    return(p);
                }
                else
                {
                    p = GetT();

                    if (GetObjectRunTime != null)
                    {
                        p = GetObjectRunTime(p, this);
                    }

                    return(p);
                }
#if  lockStack == true
            }
#endif
#endif
            }
        }