コード例 #1
0
        /// <summary>
        ///     Dispose all un-released items in the poll storage and the pool itself
        /// </summary>
        public void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed = true;
            // Do we have items in the store and does the item support the IDisposable interface?
            if (ItemStore.Count > 0 && typeof(IDisposable).IsAssignableFrom(typeof(T)))
            {
                // If so, try to dispose all unreleased items from the storage
                lock (ItemStore) {
                    do
                    {
                        var disposable = (IDisposable)ItemStore.Fetch();
                        // Avoid expensive exceptions
                        if (disposable == null)
                        {
                            continue;
                        }

                        try {
                            disposable.Dispose();
                        } catch {
                        }
                    } while (ItemStore.Count > 0);
                }
            }

            // Close the semaphore
            _sync.Close();
        }
コード例 #2
0
 public override T GetItem()
 {
     if (ItemStore.Count > 0)
     {
         return(ItemStore.Fetch());
     }
     return(factory());
 }
コード例 #3
0
ファイル: EagerPool.cs プロジェクト: GodLesZ/ZeusEngine
        public override T Acquire()
        {
            _sync.WaitOne();

            lock (ItemStore) {
                return(ItemStore.Fetch());
            }
        }
コード例 #4
0
        public override T Acquire()
        {
            _sync.WaitOne();

            // Try to get it from the pool of already released items
            lock (ItemStore) {
                if (ItemStore.Count > 0)
                {
                    return(ItemStore.Fetch());
                }
            }

            // Raise amount of lazy-loaded items
            var tmp = LazyLoadedItemCount;

            Interlocked.Increment(ref tmp);
            LazyLoadedItemCount = tmp;
            // Fetch a new item
            return(ItemFactoryFunc(this));
        }
コード例 #5
0
ファイル: EagerManager.cs プロジェクト: vyakhir/pooling
 public override T GetItem()
 {
     return(ItemStore.Fetch());
 }