15
15
using System . Transactions ;
16
16
using Microsoft . Data . Common ;
17
17
using Microsoft . Data . SqlClient ;
18
+ using static Microsoft . Data . ProviderBase . DbConnectionPoolState ;
18
19
19
20
namespace Microsoft . Data . ProviderBase
20
21
{
21
- internal sealed class DbConnectionPool : IDbConnectionPool
22
+ internal sealed class WaitHandleDbConnectionPool : DbConnectionPool
22
23
{
23
- private enum State
24
- {
25
- Initializing ,
26
- Running ,
27
- ShuttingDown ,
28
- }
29
-
30
24
// This class is a way to stash our cloned Tx key for later disposal when it's no longer needed.
31
25
// We can't get at the key in the dictionary without enumerating entries, so we stash an extra
32
26
// copy as part of the value.
@@ -390,8 +384,6 @@ internal WaitHandle[] GetHandles(bool withCreate)
390
384
/// </summary>
391
385
private readonly ConcurrentDictionary < DbConnectionPoolAuthenticationContextKey , DbConnectionPoolAuthenticationContext > _pooledDbAuthenticationContexts ;
392
386
393
- private State _state ;
394
-
395
387
private readonly ConcurrentStack < DbConnectionInternal > _stackOld = new ConcurrentStack < DbConnectionInternal > ( ) ;
396
388
private readonly ConcurrentStack < DbConnectionInternal > _stackNew = new ConcurrentStack < DbConnectionInternal > ( ) ;
397
389
@@ -417,7 +409,7 @@ internal WaitHandle[] GetHandles(bool withCreate)
417
409
private int _totalObjects ;
418
410
419
411
// only created by DbConnectionPoolGroup.GetConnectionPool
420
- internal DbConnectionPool (
412
+ internal WaitHandleDbConnectionPool (
421
413
DbConnectionFactory connectionFactory ,
422
414
DbConnectionPoolGroup connectionPoolGroup ,
423
415
DbConnectionPoolIdentity identity ,
@@ -430,7 +422,7 @@ internal DbConnectionPool(
430
422
throw ADP . InternalError ( ADP . InternalErrorCode . AttemptingToPoolOnRestrictedToken ) ;
431
423
}
432
424
433
- _state = State . Initializing ;
425
+ State = Initializing ;
434
426
435
427
lock ( s_random )
436
428
{
@@ -457,7 +449,7 @@ internal DbConnectionPool(
457
449
_transactedConnectionPool = new TransactedConnectionPool ( this ) ;
458
450
459
451
_poolCreateRequest = new WaitCallback ( PoolCreateRequest ) ; // used by CleanupCallback
460
- _state = State . Running ;
452
+ State = Running ;
461
453
SqlClientEventSource . Log . TryPoolerTraceEvent ( "<prov.DbConnectionPool.DbConnectionPool|RES|CPOOL> {0}, Constructed." , ObjectID ) ;
462
454
463
455
//_cleanupTimer & QueuePoolCreateRequest is delayed until DbConnectionPoolGroup calls
@@ -498,7 +490,7 @@ private bool NeedToReplenish
498
490
{
499
491
get
500
492
{
501
- if ( State . Running != _state ) // Don't allow connection create when not running.
493
+ if ( State != Running ) // Don't allow connection create when not running.
502
494
return false ;
503
495
504
496
int totalObjects = Count ;
@@ -524,7 +516,7 @@ internal override DbConnectionPoolIdentity Identity
524
516
525
517
internal override bool IsRunning
526
518
{
527
- get { return State . Running == _state ; }
519
+ get { return State == Running ; }
528
520
}
529
521
530
522
private int MaxPoolSize
@@ -812,20 +804,6 @@ private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectio
812
804
#endif
813
805
}
814
806
815
- // If the old connection belonged to another pool, we need to remove it from that
816
- if ( oldConnection != null )
817
- {
818
- var oldConnectionPool = oldConnection . Pool ;
819
- if ( oldConnectionPool != null && oldConnectionPool != this )
820
- {
821
- Debug . Assert ( oldConnectionPool . _state == State . ShuttingDown , "Old connections pool should be shutting down" ) ;
822
- lock ( oldConnectionPool . _objectList )
823
- {
824
- oldConnectionPool . _objectList . Remove ( oldConnection ) ;
825
- oldConnectionPool . _totalObjects = oldConnectionPool . _objectList . Count ;
826
- }
827
- }
828
- }
829
807
SqlClientEventSource . Log . TryPoolerTraceEvent ( "<prov.DbConnectionPool.CreateObject|RES|CPOOL> {0}, Connection {1}, Added to pool." , ObjectID , newObj ? . ObjectID ) ;
830
808
831
809
// Reset the error wait:
@@ -913,7 +891,7 @@ private void DeactivateObject(DbConnectionInternal obj)
913
891
{
914
892
// NOTE: constructor should ensure that current state cannot be State.Initializing, so it can only
915
893
// be State.Running or State.ShuttingDown
916
- Debug . Assert ( _state == State . Running || _state == State . ShuttingDown ) ;
894
+ Debug . Assert ( State == Running || State == ShuttingDown ) ;
917
895
918
896
lock ( obj )
919
897
{
@@ -923,7 +901,7 @@ private void DeactivateObject(DbConnectionInternal obj)
923
901
// transaction object will ensure that it is owned (not lost),
924
902
// and it will be certain to put it back into the pool.
925
903
926
- if ( _state == State . ShuttingDown )
904
+ if ( State == ShuttingDown )
927
905
{
928
906
if ( obj . IsTransactionRoot )
929
907
{
@@ -1237,7 +1215,7 @@ internal override bool TryGetConnection(DbConnection owningObject, TaskCompletio
1237
1215
allowCreate = true ;
1238
1216
}
1239
1217
1240
- if ( _state != State . Running )
1218
+ if ( State != Running )
1241
1219
{
1242
1220
SqlClientEventSource . Log . TryPoolerTraceEvent ( "<prov.DbConnectionPool.GetConnection|RES|CPOOL> {0}, DbConnectionInternal State != Running." , ObjectID ) ;
1243
1221
connection = null ;
@@ -1615,7 +1593,7 @@ private void PoolCreateRequest(object state)
1615
1593
long scopeID = SqlClientEventSource . Log . TryPoolerScopeEnterEvent ( "<prov.DbConnectionPool.PoolCreateRequest|RES|INFO|CPOOL> {0}" , ObjectID ) ;
1616
1594
try
1617
1595
{
1618
- if ( State . Running == _state )
1596
+ if ( State == Running )
1619
1597
{
1620
1598
// in case WaitForPendingOpen ever failed with no subsequent OpenAsync calls,
1621
1599
// start it back up again
@@ -1804,7 +1782,7 @@ internal override void PutObjectFromTransactedPool(DbConnectionInternal obj)
1804
1782
// done and all transactions are ended.
1805
1783
SqlClientEventSource . Log . TryPoolerTraceEvent ( "<prov.DbConnectionPool.PutObjectFromTransactedPool|RES|CPOOL> {0}, Connection {1}, Transaction has ended." , ObjectID , obj . ObjectID ) ;
1806
1784
1807
- if ( _state == State . Running && obj . CanBePooled )
1785
+ if ( State == Running && obj . CanBePooled )
1808
1786
{
1809
1787
PutNewObject ( obj ) ;
1810
1788
}
@@ -1817,7 +1795,7 @@ internal override void PutObjectFromTransactedPool(DbConnectionInternal obj)
1817
1795
1818
1796
private void QueuePoolCreateRequest ( )
1819
1797
{
1820
- if ( State . Running == _state )
1798
+ if ( State == Running )
1821
1799
{
1822
1800
// Make sure we're at quota by posting a callback to the threadpool.
1823
1801
ThreadPool . QueueUserWorkItem ( _poolCreateRequest ) ;
@@ -1908,7 +1886,7 @@ internal override void Startup()
1908
1886
internal override void Shutdown ( )
1909
1887
{
1910
1888
SqlClientEventSource . Log . TryPoolerTraceEvent ( "<prov.DbConnectionPool.Shutdown|RES|INFO|CPOOL> {0}" , ObjectID ) ;
1911
- _state = State . ShuttingDown ;
1889
+ State = ShuttingDown ;
1912
1890
1913
1891
// deactivate timer callbacks
1914
1892
Timer t = _cleanupTimer ;
0 commit comments