Esempio n. 1
0
        internal static void Add(string fileName, SQLiteConnectionHandle handle, int version)
        {
            SQLiteConnectionPool.PoolQueue poolQueue;
            ISQLiteConnectionPool          connectionPool = SQLiteConnectionPool.GetConnectionPool();

            if (connectionPool != null)
            {
                connectionPool.Add(fileName, handle, version);
                return;
            }
            lock (SQLiteConnectionPool._syncRoot)
            {
                if (!SQLiteConnectionPool._queueList.TryGetValue(fileName, out poolQueue) || version != poolQueue.PoolVersion)
                {
                    handle.Close();
                }
                else
                {
                    SQLiteConnectionPool.ResizePool(poolQueue, true);
                    Queue <WeakReference> queue = poolQueue.Queue;
                    if (queue != null)
                    {
                        queue.Enqueue(new WeakReference(handle, false));
                        Interlocked.Increment(ref SQLiteConnectionPool._poolClosed);
                    }
                    else
                    {
                        return;
                    }
                }
                GC.KeepAlive(handle);
            }
        }
Esempio n. 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);
        }