Exemplo n.º 1
0
 internal Enumerator(SparseQueue <T> q)
 {
     this._q              = q;
     this._version        = this._q._version;
     this._index          = -1;
     this._currentElement = default(T);
 }
Exemplo n.º 2
0
 private static void Clear(Dictionary <TKey, SparseQueue <TValue> > pools, Action <TKey, TValue> disposeValueCallback)
 {
     foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair in pools)
     {
         SparseQueue <TValue> queue = pair.Value;
         foreach (TValue local in queue)
         {
             disposeValueCallback(pair.Key, local);
         }
         queue.Clear();
         queue.TrimExcess();
     }
 }
Exemplo n.º 3
0
        public ObjectPoolTicket <TValue> Get(TKey key)
        {
            object sync = this.sync;

            lock (sync)
            {
                SparseQueue <TValue> queue;
                if (!this.pools.TryGetValue(key, out queue))
                {
                    queue = new SparseQueue <TValue>();
                    this.pools.Add(key, queue);
                }
                if (queue.Any <TValue>())
                {
                    return(new Ticket <TKey, TValue>((ObjectPool <TKey, TValue>) this, key, queue.Dequeue()));
                }
            }
            return(new Ticket <TKey, TValue>((ObjectPool <TKey, TValue>) this, key, this.valueFactory(key)));
        }
Exemplo n.º 4
0
        private void Return(TKey key, TValue value)
        {
            object sync = this.sync;

            lock (sync)
            {
                if (this.IsDisposed)
                {
                    this.disposeValueCallback(key, value);
                }
                else
                {
                    SparseQueue <TValue> queue;
                    if (!this.pools.TryGetValue(key, out queue))
                    {
                        queue = new SparseQueue <TValue>();
                        this.pools.Add(key, queue);
                    }
                    queue.Enqueue(value);
                }
            }
        }
Exemplo n.º 5
0
        public void TrimExcess()
        {
            SegmentedList <KeyValuePair <TKey, SparseQueue <TValue> > > list = null;
            object sync = this.sync;

            lock (sync)
            {
                foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair in this.pools)
                {
                    SparseQueue <TValue> collection = pair.Value;
                    if (collection.Any <TValue>())
                    {
                        collection.TrimExcess();
                    }
                    else
                    {
                        if (list == null)
                        {
                            list = new SegmentedList <KeyValuePair <TKey, SparseQueue <TValue> > >();
                        }
                        list.Add(pair);
                    }
                }
                if (list != null)
                {
                    foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair2 in list)
                    {
                        this.pools.Remove(pair2.Key);
                    }
                }
            }
            foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair3 in list)
            {
                pair3.Value.TrimExcess();
            }
        }
Exemplo n.º 6
0
 public void Dispose()
 {
     this._q = null;
     this._currentElement = default(T);
 }