Skip to content

Commit 899ac35

Browse files
committed
Merge pull request #13 from zerhacken/dev/fix-storage-weak-identity-lock
Fix warning CA2002: Do not lock on objects with weak identity
2 parents 098d3b5 + 0335d1a commit 899ac35

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/OrleansProviders/Storage/HierarchicalKeyStore.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ internal class HierarchicalKeyStore : MarshalByRefObject, ILocalDataStore
4141
[NonSerialized]
4242
private readonly IDictionary<string, IDictionary<string, object>> dataTable;
4343
private readonly int numKeyLayers;
44+
private readonly object lockable = new object();
4445

4546
public HierarchicalKeyStore(int keyLayers)
4647
{
@@ -57,7 +58,7 @@ public string WriteRow(IList<Tuple<string, string>> keys, IDictionary<string, ob
5758
throw new ArgumentOutOfRangeException("keys", keys.Count, error);
5859
}
5960

60-
lock (this)
61+
lock (lockable)
6162
{
6263
var storedData = GetDataStore(keys);
6364

@@ -85,7 +86,7 @@ public IDictionary<string, object> ReadRow(IList<Tuple<string, string>> keys)
8586
throw new ArgumentOutOfRangeException("keys", keys.Count, error);
8687
}
8788

88-
lock (this)
89+
lock (lockable)
8990
{
9091
IDictionary<string, object> data = GetDataStore(keys);
9192

@@ -105,7 +106,7 @@ public IList<IDictionary<string, object>> ReadMultiRow(IList<Tuple<string, strin
105106
string.Format("Too many key supplied -- Expected count = {0} Received = {1}", numKeyLayers, keys.Count));
106107
}
107108

108-
lock (this)
109+
lock (lockable)
109110
{
110111
IList<IDictionary<string, object>> results = FindDataStores(keys);
111112
#if DEBUG
@@ -127,7 +128,7 @@ public bool DeleteRow(IList<Tuple<string, string>> keys, string eTag)
127128
string keyStr = MakeStoreKey(keys);
128129

129130
bool removedEntry = false;
130-
lock (this)
131+
lock (lockable)
131132
{
132133
IDictionary<string, object> data;
133134
if (dataTable.TryGetValue(keyStr, out data))
@@ -153,7 +154,7 @@ public void Clear()
153154
#if DEBUG
154155
Trace.TraceInformation("Clear Table");
155156
#endif
156-
lock (this)
157+
lock (lockable)
157158
{
158159
dataTable.Clear();
159160
}
@@ -162,7 +163,7 @@ public void Clear()
162163
public string DumpData(bool printDump = true)
163164
{
164165
var sb = new StringBuilder();
165-
lock (this)
166+
lock (lockable)
166167
{
167168
string[] keys = dataTable.Keys.ToArray();
168169
foreach (var key in keys)
@@ -184,7 +185,7 @@ private IDictionary<string, object> GetDataStore(IList<Tuple<string, string>> ke
184185
{
185186
string keyStr = MakeStoreKey(keys);
186187

187-
lock (this)
188+
lock (lockable)
188189
{
189190
IDictionary<string, object> data;
190191
if (dataTable.ContainsKey(keyStr))
@@ -215,7 +216,7 @@ private IList<IDictionary<string, object>> FindDataStores(IList<Tuple<string, st
215216
{
216217
string keyStr = MakeStoreKey(keys);
217218

218-
lock (this)
219+
lock (lockable)
219220
{
220221
foreach (var key in dataTable.Keys)
221222
if (key.StartsWith(keyStr))

src/OrleansRuntime/GrainTypeManager/GrainTypeManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ internal class GrainTypeManager
3737
private readonly TraceLogger logger = TraceLogger.GetLogger("GrainTypeManager");
3838
private readonly GrainInterfaceMap grainInterfaceMap;
3939
private readonly Dictionary<int, InvokerData> invokers = new Dictionary<int, InvokerData>();
40+
private static readonly object lockable = new object();
4041

4142
public static GrainTypeManager Instance { get; private set; }
4243

@@ -50,7 +51,7 @@ public static void Stop()
5051
public GrainTypeManager(bool localTestMode)
5152
{
5253
grainInterfaceMap = new GrainInterfaceMap(localTestMode);
53-
lock (typeof (GrainTypeManager))
54+
lock (lockable)
5455
{
5556
if (Instance != null)
5657
throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager.");

src/OrleansRuntime/Silo/Silo.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public SiloType Type
9393
private readonly TimeSpan stopTimeout = TimeSpan.FromMinutes(1);
9494
private readonly Catalog catalog;
9595
private readonly List<IHealthCheckParticipant> healthCheckParticipants;
96+
private readonly object lockable = new object();
9697

9798

9899
internal readonly string Name;
@@ -357,7 +358,7 @@ public void Start()
357358

358359
private void DoStart()
359360
{
360-
lock (this)
361+
lock (lockable)
361362
{
362363
if (SystemStatus.Current != SystemStatus.Created)
363364
throw new InvalidOperationException(String.Format("Calling Silo.Start() on a silo which is not in the Start state. This silo is in the {0} state.", SystemStatus.Current));
@@ -523,7 +524,7 @@ private void ConfigureThreadPoolAndServicePointSettings()
523524
public void Stop()
524525
{
525526
bool stopAlreadyInProgress = false;
526-
lock (this)
527+
lock (lockable)
527528
{
528529
if (SystemStatus.Current.Equals(SystemStatus.Stopping) ||
529530
SystemStatus.Current.Equals(SystemStatus.ShuttingDown) ||
@@ -649,7 +650,7 @@ private void HandleProcessExit(object sender, EventArgs e)
649650

650651
try
651652
{
652-
lock (this)
653+
lock (lockable)
653654
{
654655
if (SystemStatus.Current != SystemStatus.Running) return;
655656

0 commit comments

Comments
 (0)