Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 9b83607

Browse files
committed
Change Active to use Interlocked to avoid thread caching
1 parent 869cfc1 commit 9b83607

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/ServiceStack.Redis/RedisNativeClient.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Net.Security;
1919
using System.Net.Sockets;
2020
using System.Text;
21+
using System.Threading;
2122
using ServiceStack.Logging;
2223
using ServiceStack.Redis.Pipeline;
2324
using ServiceStack.Text;
@@ -58,10 +59,24 @@ public partial class RedisNativeClient
5859
private IRedisPipelineShared pipeline;
5960

6061
private Dictionary<string, string> info;
62+
63+
const int YES = 1;
64+
const int NO = 0;
65+
6166
/// <summary>
6267
/// Used to manage connection pooling
6368
/// </summary>
64-
internal bool Active { get; set; }
69+
private int active;
70+
internal bool Active
71+
{
72+
get { return Interlocked.CompareExchange(ref active, 0, 0) == YES; }
73+
set
74+
{
75+
var intValue = value ? YES : NO;
76+
Interlocked.CompareExchange(ref active, intValue, active);
77+
}
78+
}
79+
6580
internal IHandleClientDispose ClientManager { get; set; }
6681

6782
internal long LastConnectedAtTimestamp;

0 commit comments

Comments
 (0)