예제 #1
0
        private static void ResizePool(SQLiteConnectionPool.PoolQueue queue, bool add)
        {
            int maxPoolSize = queue.MaxPoolSize;

            if (add && maxPoolSize > 0)
            {
                maxPoolSize--;
            }
            Queue <WeakReference> weakReferences = queue.Queue;

            if (weakReferences == null)
            {
                return;
            }
            while (weakReferences.Count > maxPoolSize)
            {
                WeakReference weakReference = weakReferences.Dequeue();
                if (weakReference == null)
                {
                    continue;
                }
                SQLiteConnectionHandle target = weakReference.Target as SQLiteConnectionHandle;
                if (target != null)
                {
                    target.Dispose();
                }
                GC.KeepAlive(target);
            }
        }
예제 #2
0
        internal static SQLiteConnectionHandle Remove(string fileName, int maxPoolSize, out int version)
        {
            int num;
            Queue <WeakReference> queue;

            SQLiteConnectionPool.PoolQueue poolQueue;
            SQLiteConnectionPool.PoolQueue poolQueue1;
            bool flag;
            SQLiteConnectionHandle sQLiteConnectionHandle;
            ISQLiteConnectionPool  connectionPool = SQLiteConnectionPool.GetConnectionPool();

            if (connectionPool != null)
            {
                return(connectionPool.Remove(fileName, maxPoolSize, out version) as SQLiteConnectionHandle);
            }
            lock (SQLiteConnectionPool._syncRoot)
            {
                version = SQLiteConnectionPool._poolVersion;
                if (SQLiteConnectionPool._queueList.TryGetValue(fileName, out poolQueue))
                {
                    int poolVersion = poolQueue.PoolVersion;
                    num     = poolVersion;
                    version = poolVersion;
                    poolQueue.MaxPoolSize = maxPoolSize;
                    SQLiteConnectionPool.ResizePool(poolQueue, false);
                    queue = poolQueue.Queue;
                    if (queue != null)
                    {
                        SQLiteConnectionPool._queueList.Remove(fileName);
                        queue = new Queue <WeakReference>(queue);
                        goto Label0;
                    }
                    else
                    {
                        sQLiteConnectionHandle = null;
                    }
                }
                else
                {
                    poolQueue = new SQLiteConnectionPool.PoolQueue(SQLiteConnectionPool._poolVersion, maxPoolSize);
                    SQLiteConnectionPool._queueList.Add(fileName, poolQueue);
                    sQLiteConnectionHandle = null;
                }
            }
            return(sQLiteConnectionHandle);

Label0:
            try
            {
                while (queue.Count > 0)
                {
                    WeakReference weakReference = queue.Dequeue();
                    if (weakReference == null)
                    {
                        continue;
                    }
                    SQLiteConnectionHandle target = weakReference.Target as SQLiteConnectionHandle;
                    if (target == null)
                    {
                        continue;
                    }
                    GC.SuppressFinalize(target);
                    try
                    {
                        GC.WaitForPendingFinalizers();
                        if (!target.IsInvalid && !target.IsClosed)
                        {
                            Interlocked.Increment(ref SQLiteConnectionPool._poolOpened);
                            sQLiteConnectionHandle = target;
                            return(sQLiteConnectionHandle);
                        }
                    }
                    finally
                    {
                        GC.ReRegisterForFinalize(target);
                    }
                    GC.KeepAlive(target);
                }
            }
            finally
            {
                lock (SQLiteConnectionPool._syncRoot)
                {
                    if (!SQLiteConnectionPool._queueList.TryGetValue(fileName, out poolQueue1))
                    {
                        flag       = true;
                        poolQueue1 = new SQLiteConnectionPool.PoolQueue(num, maxPoolSize);
                    }
                    else
                    {
                        flag = false;
                    }
                    Queue <WeakReference> weakReferences = poolQueue1.Queue;
                    while (queue.Count > 0)
                    {
                        weakReferences.Enqueue(queue.Dequeue());
                    }
                    SQLiteConnectionPool.ResizePool(poolQueue1, false);
                    if (flag)
                    {
                        SQLiteConnectionPool._queueList.Add(fileName, poolQueue1);
                    }
                }
            }
            return(null);
        }