diff --git a/src/OrleansProviders/Storage/HierarchicalKeyStore.cs b/src/OrleansProviders/Storage/HierarchicalKeyStore.cs index 3dc1903958f..33a93f7ff5e 100644 --- a/src/OrleansProviders/Storage/HierarchicalKeyStore.cs +++ b/src/OrleansProviders/Storage/HierarchicalKeyStore.cs @@ -41,6 +41,7 @@ internal class HierarchicalKeyStore : MarshalByRefObject, ILocalDataStore [NonSerialized] private readonly IDictionary> dataTable; private readonly int numKeyLayers; + private readonly object lockable = new object(); public HierarchicalKeyStore(int keyLayers) { @@ -57,7 +58,7 @@ public string WriteRow(IList> keys, IDictionary ReadRow(IList> keys) throw new ArgumentOutOfRangeException("keys", keys.Count, error); } - lock (this) + lock (lockable) { IDictionary data = GetDataStore(keys); @@ -105,7 +106,7 @@ public IList> ReadMultiRow(IList> results = FindDataStores(keys); #if DEBUG @@ -127,7 +128,7 @@ public bool DeleteRow(IList> keys, string eTag) string keyStr = MakeStoreKey(keys); bool removedEntry = false; - lock (this) + lock (lockable) { IDictionary data; if (dataTable.TryGetValue(keyStr, out data)) @@ -153,7 +154,7 @@ public void Clear() #if DEBUG Trace.TraceInformation("Clear Table"); #endif - lock (this) + lock (lockable) { dataTable.Clear(); } @@ -162,7 +163,7 @@ public void Clear() public string DumpData(bool printDump = true) { var sb = new StringBuilder(); - lock (this) + lock (lockable) { string[] keys = dataTable.Keys.ToArray(); foreach (var key in keys) @@ -184,7 +185,7 @@ private IDictionary GetDataStore(IList> ke { string keyStr = MakeStoreKey(keys); - lock (this) + lock (lockable) { IDictionary data; if (dataTable.ContainsKey(keyStr)) @@ -215,7 +216,7 @@ private IList> FindDataStores(IList invokers = new Dictionary(); + private static readonly object lockable = new object(); public static GrainTypeManager Instance { get; private set; } @@ -50,7 +51,7 @@ public static void Stop() public GrainTypeManager(bool localTestMode) { grainInterfaceMap = new GrainInterfaceMap(localTestMode); - lock (typeof (GrainTypeManager)) + lock (lockable) { if (Instance != null) throw new InvalidOperationException("An attempt to create a second insance of GrainTypeManager."); diff --git a/src/OrleansRuntime/Silo/Silo.cs b/src/OrleansRuntime/Silo/Silo.cs index 33deea49986..211ba7f40bb 100644 --- a/src/OrleansRuntime/Silo/Silo.cs +++ b/src/OrleansRuntime/Silo/Silo.cs @@ -93,6 +93,7 @@ public SiloType Type private readonly TimeSpan stopTimeout = TimeSpan.FromMinutes(1); private readonly Catalog catalog; private readonly List healthCheckParticipants; + private readonly object lockable = new object(); internal readonly string Name; @@ -357,7 +358,7 @@ public void Start() private void DoStart() { - lock (this) + lock (lockable) { if (SystemStatus.Current != SystemStatus.Created) 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() public void Stop() { bool stopAlreadyInProgress = false; - lock (this) + lock (lockable) { if (SystemStatus.Current.Equals(SystemStatus.Stopping) || SystemStatus.Current.Equals(SystemStatus.ShuttingDown) || @@ -649,7 +650,7 @@ private void HandleProcessExit(object sender, EventArgs e) try { - lock (this) + lock (lockable) { if (SystemStatus.Current != SystemStatus.Running) return;