Skip to content

Commit b687162

Browse files
committed
simplify counting
1 parent 8c660e8 commit b687162

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/StackExchange.Redis/ConnectionMultiplexer.Debug.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@ namespace StackExchange.Redis;
44

55
public partial class ConnectionMultiplexer
66
{
7-
private static int _collectedWithoutDispose, s_MuxerDestroyCount, s_MuxerCreateCount;
7+
private static int _collectedWithoutDispose, s_DisposedCount, s_MuxerCreateCount;
88
internal static int CollectedWithoutDispose => Volatile.Read(ref _collectedWithoutDispose);
99

10-
internal static int GetLiveObjectCount(out int created, out int destroyed, out int nonDisposed)
10+
internal static int GetLiveObjectCount(out int created, out int disposed, out int finalized)
1111
{
1212
// read destroy first, to prevent negative numbers in race conditions
13-
destroyed = Volatile.Read(ref s_MuxerDestroyCount);
13+
disposed = Volatile.Read(ref s_DisposedCount);
1414
created = Volatile.Read(ref s_MuxerCreateCount);
15-
nonDisposed = Volatile.Read(ref _collectedWithoutDispose);
16-
return created - destroyed;
15+
finalized = Volatile.Read(ref _collectedWithoutDispose);
16+
return created - (disposed + finalized);
1717
}
1818

1919
/// <summary>
2020
/// Invoked by the garbage collector.
2121
/// </summary>
2222
~ConnectionMultiplexer()
2323
{
24-
Interlocked.Increment(ref s_MuxerDestroyCount);
2524
Interlocked.Increment(ref _collectedWithoutDispose);
2625
}
2726

src/StackExchange.Redis/ConnectionMultiplexer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,8 +2260,8 @@ ConfigurationChangedChannel is byte[] channel
22602260
public void Dispose()
22612261
{
22622262
GC.SuppressFinalize(this);
2263-
Interlocked.Increment(ref s_MuxerDestroyCount);
2264-
Close(!_isDisposed);
2263+
if (!_isDisposed) Interlocked.Increment(ref s_DisposedCount);
2264+
Close(!_isDisposed); // marks disposed
22652265
sentinelConnection?.Dispose();
22662266
var oldTimer = Interlocked.Exchange(ref sentinelPrimaryReconnectTimer, null);
22672267
oldTimer?.Dispose();
@@ -2273,8 +2273,8 @@ public void Dispose()
22732273
public async ValueTask DisposeAsync()
22742274
{
22752275
GC.SuppressFinalize(this);
2276-
Interlocked.Increment(ref s_MuxerDestroyCount);
2277-
await CloseAsync(!_isDisposed).ForAwait();
2276+
if (!_isDisposed) Interlocked.Increment(ref s_DisposedCount);
2277+
await CloseAsync(!_isDisposed).ForAwait(); // marks disposed
22782278
if (sentinelConnection is ConnectionMultiplexer sentinel)
22792279
{
22802280
await sentinel.DisposeAsync().ForAwait();

src/StackExchange.Redis/ExceptionFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ private static void AddCommonDetail(
347347
Add(data, sb, "Last-Result-Bytes", "last-in", bs.Connection.BytesLastResult.ToString());
348348
Add(data, sb, "Inbound-Buffer-Bytes", "cur-in", bs.Connection.BytesInBuffer.ToString());
349349

350-
var liveMuxers = ConnectionMultiplexer.GetLiveObjectCount(out var created, out var destroyed, out var nonDisposed);
350+
var liveMuxers = ConnectionMultiplexer.GetLiveObjectCount(out var created, out var disposed, out var finalized);
351351
if (created > 1)
352352
{
353-
Add(data, sb, "Live-Multiplexers", "lm", $"{liveMuxers}/{created}/{destroyed}/{nonDisposed}");
353+
Add(data, sb, "Live-Multiplexers", "lm", $"{liveMuxers}/{created}/{disposed}/{finalized}");
354354
}
355355

356356
Add(data, sb, "Sync-Ops", "sync-ops", multiplexer.syncOps.ToString());

0 commit comments

Comments
 (0)