未验证 提交 4b759636 编写于 作者: L lindexi 提交者: GitHub

Make some lock object as readonly (#4487)

上级 d21ce7a8
......@@ -156,7 +156,7 @@ public static DynamicIndexerAccessor GetIndexerAccessor(int rank)
MulticastDelegate _getterDelegate, _setterDelegate;
static DynamicIndexerAccessor[] _accessors = new DynamicIndexerAccessor[1];
static object _lock = new object();
static readonly object _lock = new object();
}
#endregion DynamicIndexerAccessor
......
......@@ -315,7 +315,7 @@ internal static string CompositeFontExtension
private const string EmptyFontFamilyReference = "#";
private const string EmptyCanonicalName = "";
private static object _dpiLock = new object();
private static readonly object _dpiLock = new object();
private static int _dpi;
private static bool _dpiInitialized = false;
......
......@@ -68,7 +68,7 @@ internal static void Add(object key, object value)
}
private static Hashtable _hashTable = new Hashtable(MaxCacheCapacity);
private static object _lock = new object();
private static readonly object _lock = new object();
private const int MaxCacheCapacity = 64; // Maximum cache capacity
}
}
......@@ -241,7 +241,7 @@ internal bool ThreadSafe
// Hashtable. HybridDictionary already has functionality of switching between
// ListDictionary and Hashtable depending on the size of the collection
static private HybridDictionary _packagePairs;
static private Object _globalLock;
static private readonly Object _globalLock;
#endregion Private Fields
}
......
......@@ -834,7 +834,7 @@ enum RECO_TYPE : ushort
/// <summary>
/// Used to lock for instancing the native recognizer handle
/// </summary>
private static object _syncRoot = new object();
private static readonly object _syncRoot = new object();
/// <summary>
/// All NativeRecognizer share a single handle to the recognizer
......
......@@ -172,7 +172,7 @@ private static void ValidatePackageUri(Uri uri)
// Hashtable. HybridDictionary already has functionality of switching between
// ListDictionary and Hashtable depending on the size of the collection
static private HybridDictionary _packages;
static private Object _globalLock;
static private readonly Object _globalLock;
#endregion Private Fields
}
......
......@@ -187,6 +187,6 @@ private static void Seal()
}
private static bool _isSealed;
private static object _lockObject = new object();
private static readonly object _lockObject = new object();
}
}
......@@ -470,7 +470,7 @@ private static void EnsurePredefined()
private static ArrayList _formatList;
// This object is for locking the _formatList to access safe in the multi-thread.
private static Object _formatListlock = new Object();
private static readonly Object _formatListlock = new Object();
#endregion Private Fields
}
......
......@@ -38,7 +38,7 @@ internal static class XamlSourceInfoHelper
private static ConditionalWeakTable<object, XamlSourceInfo> s_sourceInfoTable; // no storage by default
// While ConditionalWeakTable is thread safe we need to make multiple calls in a thread safe manner.
private static object s_lock = new object();
private static readonly object s_lock = new object();
private static PropertyInfo s_sourceBamlUriProperty;
private static PropertyInfo s_elementLineNumberProperty;
......
......@@ -98,7 +98,7 @@ private static EventRoute Pop()
private static EventRoute[] _eventRouteStack;
private static int _stackTop;
private static object _synchronized = new object();
private static readonly object _synchronized = new object();
#endregion Data
}
......
......@@ -1005,7 +1005,7 @@ private void RequestContinueProcessingStagingArea()
private static DispatcherOperation _synchronizedInputAsyncClearOperation;
// Lock used to serialize access to synchronized input related static fields.
private static object _synchronizedInputLock = new object();
private static readonly object _synchronizedInputLock = new object();
}
}
......@@ -1234,7 +1234,7 @@ private void DestroyRealTimeVisuals()
// For OnRenderComplete support (for UI Thread)
EventHandler _onRenderComplete;
bool _waitingForRenderComplete;
object __siLock = new object();
readonly object __siLock = new object();
private StrokeInfo _renderCompleteStrokeInfo;
// On internal real time ink rendering thread.
......
......@@ -3673,11 +3673,11 @@ internal long IncrementVersion()
bool _inputEnabled = false;
bool _updatingScreenMeasurements = false;
DispatcherOperationCallback _processDisplayChanged;
object __penContextsLock = new object();
readonly object __penContextsLock = new object();
Dictionary<object, PenContexts> __penContextsMap = new Dictionary<object, PenContexts>(2);
object __stylusDeviceLock = new object();
readonly object __stylusDeviceLock = new object();
Dictionary<int, StylusDevice> __stylusDeviceMap = new Dictionary<int, StylusDevice>(2);
bool _inDragDrop;
......
......@@ -139,7 +139,7 @@ internal IntPtr ImagingFactoryPtr
/// "FactoryMaker" is free threaded. This lock is used to synchronize
/// access to the FactoryMaker.
/// </summary>
private static object s_factoryMakerLock = new object();
private static readonly object s_factoryMakerLock = new object();
private bool _fValidObject;
}
}
......
......@@ -1687,7 +1687,7 @@ internal bool CanConvertToString()
internal UniqueEventHelper<ExceptionEventArgs> _failedEvent = new UniqueEventHelper<ExceptionEventArgs>();
/// SyncObject
private object _syncObject = new Object();
private readonly object _syncObject = new Object();
// For UnmanagedMemoryStream we want to make sure that buffer
// its pointing to is not getting release until decoder is alive
......
......@@ -472,7 +472,7 @@ Exception e
private static Thread _thread;
/// lock object
private static object _syncLock;
private static readonly object _syncLock;
/// Default async read size
private const int READ_SIZE = 1024;
......
......@@ -35,7 +35,7 @@ namespace System.Windows.Media.TextFormatting
/// </summary>
public abstract class TextFormatter : IDisposable
{
private static object _staticLock = new object();
private static readonly object _staticLock = new object();
/// <summary>
/// Client to create a new instance of TextFormatter
......
......@@ -792,7 +792,7 @@ private static PresentationSource FindSource(DependencyObject o, bool enable2DTo
private static readonly RoutedEvent SourceChangedEvent = EventManager.RegisterRoutedEvent("SourceChanged", RoutingStrategy.Direct, typeof(SourceChangedEventHandler), typeof(PresentationSource));
// The lock we use to protect our static data.
private static object _globalLock = new object();
private static readonly object _globalLock = new object();
// An array of weak-references to sources that we know about.
private static WeakReferenceList _sources = new WeakReferenceList(_globalLock);
......
......@@ -427,7 +427,7 @@ internal class InternetSecurityManager
// Object to be used for locking. Using typeof(Util) causes an FxCop
// violation DoNotLockOnObjectsWithWeakIdentity
private static object _lockObj = new object();
private static readonly object _lockObj = new object();
private static UnsafeNativeMethods.IInternetSecurityManager _secMgr;
......
......@@ -104,7 +104,7 @@ private void ExtractDisallowedRegistryList()
static SecurityCriticalDataForSet<bool> _disallowedListExtracted;
static object _lock = new object();
static readonly object _lock = new object();
private const string FILEVERSION_STRING = @", FileVersion=";
// This is the location in the registry where all the keys are stored
......
......@@ -185,7 +185,7 @@ private Stream EnsureResourceLocationSet()
private SecurityCriticalDataForSet<ResourceManagerWrapper> _rmWrapper;
private bool _ensureResourceIsCalled = false;
private string _name;
private Object _globalLock = new Object();
private readonly Object _globalLock = new Object();
#endregion Private Members
}
......
......@@ -219,7 +219,7 @@ bool ChangeStatus(AsyncRequestStatus newStatus)
AsyncRequestCallback _workCallback;
AsyncRequestCallback _completedCallback;
object SyncRoot = new object(); // for synchronization
readonly object SyncRoot = new object(); // for synchronization
}
......
......@@ -755,7 +755,7 @@ internal override void OnShutDown(object target, object sender, EventArgs e)
private CleanupHelper _cleanupHelper;
private Queue<DataBindOperation> _crossThreadQueue = new Queue<DataBindOperation>();
private object _crossThreadQueueLock = new object();
private readonly object _crossThreadQueueLock = new object();
private int _crossThreadCost;
private DispatcherOperation _crossThreadDispatcherOperation;
internal const int CrossThreadThreshold = 50000; // 50 msec
......
......@@ -799,7 +799,7 @@ object IEnumerator.Current
static List<DependencyProperty> s_dpList = new List<DependencyProperty>();
// static list of DPs, shared by all instances of lists
static object s_Sync = new object(); // lock for s_dpList
static readonly object s_Sync = new object(); // lock for s_dpList
#endregion
}
......
......@@ -215,7 +215,7 @@ private static void OnUpdateHighContrast(HighContrastCallback highContrastCallba
#region Private Fields
private static object __lock = new object();
private static readonly object __lock = new object();
private static List<WeakReference> __highContrastCallbackList;
private static int __increaseCount;
private const int CleanTolerance = 100;
......
......@@ -765,7 +765,7 @@ private unsafe void InitTableObjInfo(PtsHost ptsHost, ref PTS.FSTABLEOBJINIT tab
/// <summary>
/// Lock.
/// </summary>
private object _lock = new object();
private readonly object _lock = new object();
/// <summary>
/// Whether object is already disposed.
......
......@@ -392,7 +392,7 @@ protected bool IsDisposed
private bool _disposed = false;
/// Private object used for synchronization
private Object lockObject = new Object();
private readonly Object lockObject = new Object();
#endregion Private Fields
}
......
......@@ -273,7 +273,7 @@ private static void RemoveResourceDictionaryForUriImpl(Uri uri, ResourceDictiona
}
private static Dictionary<Uri, List<WeakReference<ResourceDictionary>>> _dictionariesFromUri;
private static object _dictionariesFromUriLock = new object();
private static readonly object _dictionariesFromUriLock = new object();
private static IReadOnlyCollection<ResourceDictionary> EmptyResourceDictionaries
=> Array.Empty<ResourceDictionary>();
......
......@@ -114,7 +114,7 @@ private class InstanceInfo
/// A lock object to serialize updates to <see cref="_instanceInfos"/>
/// and the <see cref="InstanceInfo"/> instances contained therein.
/// </summary>
private static object _lockObject = new object();
private static readonly object _lockObject = new object();
/// <summary>
/// The current COM action being tracked
......@@ -298,4 +298,4 @@ private struct SpellerCOMTimingData
public long RunningAverageCallTimeForCOMCallsMs { get; set; }
}
}
}
\ No newline at end of file
}
......@@ -478,6 +478,6 @@ private static void Seal()
}
private static bool _isSealed;
private static object _lockObject = new object();
private static readonly object _lockObject = new object();
}
}
......@@ -1320,7 +1320,7 @@ private bool IsValueDefined(DependencyProperty dp)
private FrameworkElementFactory _nextSibling;
// Instance-based synchronization
private object _synchronized = new object();
private readonly object _synchronized = new object();
}
}
......@@ -708,7 +708,7 @@ private bool TryGetBamlProperty(Int16 propertyId, out BamlProperty bamlProperty,
private static readonly Lazy<XamlType> _staticResourceExtensionType
= new Lazy<XamlType>(() => System.Windows.Markup.XamlReader.BamlSharedSchemaContext.GetXamlType(typeof(StaticResourceExtension)));
private object _syncObject = new object();
private readonly object _syncObject = new object();
private Assembly _localAssembly;
......
......@@ -64,7 +64,7 @@ internal XamlType GetXamlTypeInternal(string xamlNamespace, string name, params
}
private Dictionary<Type, XamlType> _masterTypeTable = new Dictionary<Type, XamlType>();
private object _syncObject = new Object();
private readonly object _syncObject = new Object();
private bool _useV3Rules;
}
}
......@@ -406,7 +406,7 @@ private bool TryGetConstructorInfoArguments(object instance, out ParameterInfo[]
return false;
}
private static object _shouldSerializeCacheLock = new object();
private static readonly object _shouldSerializeCacheLock = new object();
private static Hashtable _shouldSerializeCache = new Hashtable();
private static Type[] _shouldSerializeArgsObject = new Type[] { typeof(DependencyObject) };
private static Type[] _shouldSerializeArgsManager = new Type[] { typeof(XamlDesignerSerializationManager) };
......
......@@ -1561,7 +1561,7 @@ private static class NamespaceCache
{
private static Dictionary<Assembly, Dictionary<string, string>> XmlnsDefinitions = new Dictionary<Assembly, Dictionary<string, string>>();
private static Dictionary<string, string> DefaultPrefixes = new Dictionary<string, string>();
private static object SyncObject = new object();
private static readonly object SyncObject = new object();
static Dictionary<string, string> GetMappingsFor(Assembly assembly)
{
......
......@@ -24,7 +24,7 @@ internal class XamlTypeMapperSchemaContext : XamlSchemaContext
WpfSharedXamlSchemaContext _sharedSchemaContext;
// Lock on syncObject
object syncObject = new object();
readonly object syncObject = new object();
Dictionary<string, string> _piNamespaces;
IEnumerable<string> _allXamlNamespaces;
Dictionary<Type, XamlType> _allowedInternalTypes;
......
......@@ -393,7 +393,7 @@ internal TriggerCondition[] TriggerConditions
/* property */ internal FrugalStructList<System.Windows.PropertyValue> PropertyValues = new FrugalStructList<System.Windows.PropertyValue>();
// Global, cross-object synchronization
private static object Synchronized = new object();
private static readonly object Synchronized = new object();
// Conditions
TriggerCondition[] _triggerConditions;
......
......@@ -51,7 +51,7 @@ internal static EventSource GetProvider()
}
private static EventSource _logger;
private static object _lockObject = new object();
private static readonly object _lockObject = new object();
#if WINDOWS_BASE
/// <summary>
......@@ -70,4 +70,4 @@ internal static EventSource GetProvider()
private static readonly string ProviderName = "Microsoft.DOTNET.WPF.PresentationFramework";
#endif
}
}
\ No newline at end of file
}
......@@ -441,7 +441,7 @@ internal static class HandleCollector
private static HandleType[] handleTypes;
private static int handleTypeCount = 0;
private static Object handleMutex = new Object();
private static readonly Object handleMutex = new Object();
/// <devdoc>
/// Adds the given handle to the handle collector. This keeps the
......
......@@ -284,7 +284,7 @@ protected Exception GetConvertFromException(object value)
TypeDescriptor.Refreshed += TypeDescriptorRefreshed;
}
private static object _valueSerializersLock = new object();
private static readonly object _valueSerializersLock = new object();
private static Hashtable _valueSerializers = new Hashtable();
}
}
......@@ -505,7 +505,7 @@ private static bool IsValidBorderStyle(object o)
/// If BorderBrush is not set to ClassicBorderBrush, a flat style is drawn
/// </summary>
private static Brush _classicBorderBrush;
private static object _brushLock = new object();
private static readonly object _brushLock = new object();
public static Brush ClassicBorderBrush
{
......
......@@ -731,7 +731,7 @@ private enum Tracker
private static QueueProcessor _callbackQueue; // callbacks are queued on this class to avoid deadlocks
private static bool _isBkgrdThreadRunning = false; // is there a background thread for queueing and recieving WinEvents?
private static ArrayList _listeners; // data representing events the client is listening for
private static object _classLock = new object(); // use lock object vs typeof(class) for perf reasons
private static readonly object _classLock = new object(); // use lock object vs typeof(class) for perf reasons
#endregion Private Fields
}
......
......@@ -828,7 +828,7 @@ private enum ProxyScoping
FallbackHandlers,
}
private static object _lockObj = new object();
private static readonly object _lockObj = new object();
// contains ClientSideProviderDescription structs or an Arraylist of ClientSideProviderDescription structs
private static Hashtable _classHandlers = new Hashtable(22, 1.0f);
......
......@@ -512,7 +512,7 @@ void Invalidate()
int _refCount = 0;
// Used to lock on this instance...
object _instanceLock = null;
readonly object _instanceLock = null;
//--- Per-Thread state ---
......
......@@ -582,7 +582,7 @@ private static void InitObjectIdMenu()
private static Hashtable _objectIdScroll;
private static Hashtable _objectIdCaret;
private static Hashtable _objectIdMenu;
private static object _classLock = new object(); // use lock object vs typeof(class) for perf
private static readonly object _classLock = new object(); // use lock object vs typeof(class) for perf
// The hwndLast and objLast is to allow limited filtering of events.
private static IntPtr _hwndLast = IntPtr.Zero;
......
......@@ -589,7 +589,7 @@ private enum EventFlag
// WinEventHooks must be processed in the same thread that created them.
// Use a seperate thread to manage the hooks
private static QueueProcessor _callbackQueue = null;
private static object _queueLock = new object();
private static readonly object _queueLock = new object();
// static: Array of Hashtables, one per WinEvent Id.
// Each Hashtable contains EventHookParams classes the key is the process id.
......
......@@ -385,6 +385,6 @@ private static void Seal()
}
private static bool _isSealed;
private static object _lockObject = new object();
private static readonly object _lockObject = new object();
}
}
......@@ -231,7 +231,7 @@ private DependencyObjectType()
// Synchronized: Covered by DispatcherLock
private static int DTypeCount = 0;
private static object _lock = new object();
private static readonly object _lock = new object();
}
}
......@@ -2879,7 +2879,7 @@ private object[] CombineParameters(object arg, object[] args)
private static List<WeakReference> _dispatchers;
private static WeakReference _possibleDispatcher;
private static object _globalLock;
private static readonly object _globalLock;
[ThreadStatic]
private static Dispatcher _tlsDispatcher; // use TLS for ownership only
......
......@@ -243,7 +243,7 @@ internal void RaiseOperationAborted(Dispatcher dispatcher, DispatcherOperation o
}
}
private object _instanceLock = new object();
private readonly object _instanceLock = new object();
private EventHandler _dispatcherInactive;
......
......@@ -319,7 +319,7 @@ private object FireTick()
}
// This is the object we use to synchronize access.
private object _instanceLock = new object();
private readonly object _instanceLock = new object();
// Note: We cannot BE a dispatcher-affinity object because we can be
// created by a worker thread. We are still associated with a
......
......@@ -308,7 +308,7 @@ public bool PreFilterMessage(ref SWF.Message msg)
internal class WeakReferenceList<T> where T : class
{
List<WeakReference> _internalList;
object _syncRoot = new object();
readonly object _syncRoot = new object();
public WeakReferenceList()
: base()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册