Exemplo n.º 1
0
        /// <summary>
        /// 放回一个
        /// </summary>
        public virtual void back(T obj)
        {
            if (obj == null)
            {
                Ctrl.throwError("对象池添加空对象");
                return;
            }

            if (!_enable || _queue.size() >= _maxSize)
            {
                if (_releaseFunc != null)
                {
                    _releaseFunc(obj);
                }

                return;
            }

            if (_needClear)
            {
                if (obj is IPoolObject)
                {
                    ((IPoolObject)obj).clear();
                }
            }


            if (ShineSetting.openCheck)
            {
                if (_checkSet.contains(obj))
                {
                    Ctrl.print("上次调用", _callStackDic.get(obj));
                    Ctrl.throwError("对象池重复添加!", obj);
                    return;
                }

                _checkSet.add(obj);
                string stackTrace = Ctrl.getStackTrace();
                stackTrace = stackTrace.Replace("\n", " ");
                _callStackDic.put(obj, stackTrace);
            }


            _queue.add(obj);
        }
Exemplo n.º 2
0
        /** 执行一次 */
        public void runOnce()
        {
            lock (_queue)
            {
                Action <T> consumer = _consumer;
                SQueue <T> queue    = _queue;

                if (!queue.isEmpty())
                {
                    for (int i = queue.size() - 1; i >= 0; --i)
                    {
                        try
                        {
                            consumer(queue.poll());
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }
                    }
                }
            }
        }