예제 #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 void ClearAllPools()
        {
            ISQLiteConnectionPool connectionPool = SQLiteConnectionPool.GetConnectionPool();

            if (connectionPool != null)
            {
                connectionPool.ClearAllPools();
                return;
            }
            lock (SQLiteConnectionPool._syncRoot)
            {
                foreach (KeyValuePair <string, SQLiteConnectionPool.PoolQueue> keyValuePair in SQLiteConnectionPool._queueList)
                {
                    if (keyValuePair.Value == null)
                    {
                        continue;
                    }
                    Queue <WeakReference> queue = keyValuePair.Value.Queue;
                    while (queue.Count > 0)
                    {
                        WeakReference weakReference = queue.Dequeue();
                        if (weakReference == null)
                        {
                            continue;
                        }
                        SQLiteConnectionHandle target = weakReference.Target as SQLiteConnectionHandle;
                        if (target != null)
                        {
                            target.Dispose();
                        }
                        GC.KeepAlive(target);
                    }
                    if (SQLiteConnectionPool._poolVersion > keyValuePair.Value.PoolVersion)
                    {
                        continue;
                    }
                    SQLiteConnectionPool._poolVersion = keyValuePair.Value.PoolVersion + 1;
                }
                SQLiteConnectionPool._queueList.Clear();
            }
        }
예제 #3
0
        internal static void ClearPool(string fileName)
        {
            SQLiteConnectionPool.PoolQueue poolQueue;
            ISQLiteConnectionPool          connectionPool = SQLiteConnectionPool.GetConnectionPool();

            if (connectionPool != null)
            {
                connectionPool.ClearPool(fileName);
                return;
            }
            lock (SQLiteConnectionPool._syncRoot)
            {
                if (SQLiteConnectionPool._queueList.TryGetValue(fileName, out poolQueue))
                {
                    poolQueue.PoolVersion++;
                    Queue <WeakReference> queue = poolQueue.Queue;
                    if (queue != null)
                    {
                        while (queue.Count > 0)
                        {
                            WeakReference weakReference = queue.Dequeue();
                            if (weakReference == null)
                            {
                                continue;
                            }
                            SQLiteConnectionHandle target = weakReference.Target as SQLiteConnectionHandle;
                            if (target != null)
                            {
                                target.Dispose();
                            }
                            GC.KeepAlive(target);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }