Skip to content

Commit 9a4af4c

Browse files
committed
Move member variables and constructor
1 parent b75c7c0 commit 9a4af4c

File tree

3 files changed

+44
-45
lines changed

3 files changed

+44
-45
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ internal static Exception ExceptionWithStackTrace(Exception e)
130130
}
131131
}
132132

133-
internal static Timer UnsafeCreateTimer(TimerCallback callback, object state, int dueTime, int period)
133+
internal static Timer UnsafeCreateTimer(TimerCallback callback, object state, int dueTime, int period) =>
134+
UnsafeCreateTimer(callback, state, TimeSpan.FromSeconds(dueTime), TimeSpan.FromSeconds(period));
135+
136+
internal static Timer UnsafeCreateTimer(TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)
134137
{
135138
// Don't capture the current ExecutionContext and its AsyncLocals onto
136139
// a global timer causing them to live forever
@@ -154,6 +157,7 @@ internal static Timer UnsafeCreateTimer(TimerCallback callback, object state, in
154157
}
155158
}
156159
}
160+
157161

158162
#region COM+ exceptions
159163
internal static ArgumentException Argument(string error)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,8 @@ namespace Microsoft.Data.ProviderBase
1818
{
1919
internal abstract class DbConnectionFactory
2020
{
21-
private Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> _connectionPoolGroups;
22-
private readonly List<IDbConnectionPool> _poolsToRelease;
23-
private readonly List<DbConnectionPoolGroup> _poolGroupsToRelease;
24-
private readonly Timer _pruningTimer;
25-
26-
private const int PruningDueTime = 4 * 60 * 1000; // 4 minutes
27-
private const int PruningPeriod = 30 * 1000; // thirty seconds
28-
29-
private static int _objectTypeCount; // EventSource counter
3021
internal int ObjectID { get; } = Interlocked.Increment(ref _objectTypeCount);
3122

32-
// s_pendingOpenNonPooled is an array of tasks used to throttle creation of non-pooled connections to
33-
// a maximum of Environment.ProcessorCount at a time.
34-
private static uint s_pendingOpenNonPooledNext = 0;
35-
private static Task<DbConnectionInternal>[] s_pendingOpenNonPooled = new Task<DbConnectionInternal>[Environment.ProcessorCount];
36-
private static Task<DbConnectionInternal> s_completedTask;
37-
38-
protected DbConnectionFactory()
39-
{
40-
_connectionPoolGroups = new Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup>();
41-
_poolsToRelease = new List<IDbConnectionPool>();
42-
_poolGroupsToRelease = new List<DbConnectionPoolGroup>();
43-
_pruningTimer = CreatePruningTimer();
44-
}
45-
46-
public abstract DbProviderFactory ProviderFactory
47-
{
48-
get;
49-
}
50-
5123
public void ClearAllPools()
5224
{
5325
using (TryEventScope.Create(nameof(SqlConnectionFactory)))
@@ -140,13 +112,6 @@ internal DbConnectionInternal CreatePooledConnection(IDbConnectionPool pool, DbC
140112
internal abstract DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo(
141113
DbConnectionOptions connectionOptions);
142114

143-
private Timer CreatePruningTimer() =>
144-
ADP.UnsafeCreateTimer(
145-
new TimerCallback(PruneConnectionPoolGroups),
146-
null,
147-
PruningDueTime,
148-
PruningPeriod);
149-
150115
protected DbConnectionOptions FindConnectionOptions(DbConnectionPoolKey key)
151116
{
152117
Debug.Assert(key != null, "key cannot be null");

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Collections.Generic;
67
using System.Data.Common;
78
using System.Diagnostics;
89
using System.IO;
910
using System.Reflection;
11+
using System.Threading;
12+
using System.Threading.Tasks;
1013
using Microsoft.Data.Common;
1114
using Microsoft.Data.Common.ConnectionString;
1215
using Microsoft.Data.ProviderBase;
@@ -20,22 +23,49 @@ namespace Microsoft.Data.SqlClient
2023
{
2124
internal sealed class SqlConnectionFactory : DbConnectionFactory
2225
{
23-
internal static readonly SqlConnectionFactory SingletonInstance = new SqlConnectionFactory();
26+
#region Member Variables
2427

25-
private SqlConnectionFactory() : base()
28+
private static readonly TimeSpan PruningDueTime = TimeSpan.FromMinutes(4);
29+
private static readonly TimeSpan PruningPeriod = TimeSpan.FromSeconds(30);
30+
31+
// s_pendingOpenNonPooled is an array of tasks used to throttle creation of non-pooled
32+
// connections to a maximum of Environment.ProcessorCount at a time.
33+
private static Task<DbConnectionInternal> s_completedTask;
34+
private static int s_objectTypeCount;
35+
private static Task<DbConnectionInternal>[] s_pendingOpenNonPooled =
36+
new Task<DbConnectionInternal>[Environment.ProcessorCount];
37+
private static uint s_pendingOpenNonPooledNext = 0;
38+
39+
private readonly List<DbConnectionPoolGroup> _poolGroupsToRelease;
40+
private readonly List<IDbConnectionPool> _poolsToRelease;
41+
private readonly Timer _pruningTimer;
42+
private Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> _connectionPoolGroups;
43+
44+
#endregion
45+
46+
#region Constructors
47+
48+
private SqlConnectionFactory()
2649
{
50+
_connectionPoolGroups = new Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup>();
51+
_poolsToRelease = new List<IDbConnectionPool>();
52+
_poolGroupsToRelease = new List<DbConnectionPoolGroup>();
53+
_pruningTimer = ADP.UnsafeCreateTimer(
54+
new TimerCallback(PruneConnectionPoolGroups),
55+
state: null,
56+
PruningDueTime,
57+
PruningPeriod);
58+
2759
#if NET
2860
SubscribeToAssemblyLoadContextUnload();
2961
#endif
3062
}
63+
64+
#endregion
3165

32-
public override DbProviderFactory ProviderFactory
33-
{
34-
get
35-
{
36-
return SqlClientFactory.Instance;
37-
}
38-
}
66+
public static readonly SqlConnectionFactory SingletonInstance = new SqlConnectionFactory();
67+
68+
public DbProviderFactory ProviderFactory => SqlClientFactory.Instance;
3969

4070
protected override DbConnectionInternal CreateConnection(
4171
DbConnectionOptions options,

0 commit comments

Comments
 (0)