WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ public Pool(ConnectionString connectionString)

public void Dispose()
{
Item[] items;

lock (_syncRoot)
{
if (_disposed)
return;
_disposed = true;
CleanConnectionsImpl();

items = _available.ToArray();
_available.Clear();
}

CleanConnectionsImpl(items);
}

public FbConnectionInternal GetConnection(out bool createdNew)
Expand Down Expand Up @@ -103,6 +109,8 @@ public void ReleaseConnection(FbConnectionInternal connection, bool returnToAvai

public void PrunePool()
{
List<Item> release;

lock (_syncRoot)
{
CheckDisposedImpl();
Expand All @@ -117,26 +125,33 @@ public void PrunePool()
{
keep = keep.Concat(available.Except(keep).OrderByDescending(x => x.Created).Take(_connectionString.MinPoolSize - keepCount)).ToList();
}
var release = available.Except(keep).ToList();
Parallel.ForEach(release, x => x.Release());
release = available.Except(keep).ToList();
_available = new Stack<Item>(keep);
}

// Call Release() outside the lock to avoid potential deadlocks
Parallel.ForEach(release, x => x.Release());
}

public void ClearPool()
{
Item[] items;

lock (_syncRoot)
{
CheckDisposedImpl();

CleanConnectionsImpl();
items = _available.ToArray();
_available.Clear();
}

// Call Release() outside the lock to avoid potential deadlocks
CleanConnectionsImpl(items);
}

void CleanConnectionsImpl()
void CleanConnectionsImpl(Item[] items)
{
Parallel.ForEach(_available, x => x.Release());
Parallel.ForEach(items, x => x.Release());
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down