Skip to content

Commit a12ce66

Browse files
authored
Merge pull request #107572 from carlossanlop/release/6.0-staging
2 parents ec3f6ab + c52f595 commit a12ce66

File tree

8 files changed

+111
-96
lines changed

8 files changed

+111
-96
lines changed

eng/pipelines/coreclr/templates/helix-queues-setup.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
# Android arm64
3434
- ${{ if in(parameters.platform, 'Android_arm64') }}:
35-
- Windows.10.Amd64.Android.Open
35+
- Windows.11.Amd64.Android.Open
3636

3737
# Android x64
3838
- ${{ if in(parameters.platform, 'Android_x64') }}:

eng/pipelines/libraries/helix-queues-setup.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
- ${{ if in(parameters.platform, 'Android_x86', 'Android_x64') }}:
9696
- Ubuntu.2204.Amd64.Android.29.Open
9797
- ${{ if in(parameters.platform, 'Android_arm', 'Android_arm64') }}:
98-
- Windows.10.Amd64.Android.Open
98+
- Windows.11.Amd64.Android.Open
9999

100100
# iOS Simulator/Mac Catalyst arm64
101101
- ${{ if in(parameters.platform, 'MacCatalyst_arm64', 'iOSSimulator_arm64') }}:

src/libraries/Native/Unix/System.Security.Cryptography.Native.Apple/pal_x509_macos.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ int32_t AppleCryptoNative_X509CopyWithPrivateKey(SecCertificateRef cert,
391391
SecKeychainItemRef itemCopy = NULL;
392392

393393
// This only happens with an ephemeral key, so the keychain we're adding it to is temporary.
394-
if (status == errSecNoSuchKeychain)
394+
if (status == errSecNoSuchKeychain || status == errSecInvalidItemRef)
395395
{
396396
status = AddKeyToKeychain(privateKey, targetKeychain, NULL);
397397
}

src/libraries/System.ComponentModel.TypeConverter/src/System.ComponentModel.TypeConverter.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
</ItemGroup>
241241
<ItemGroup>
242242
<Reference Include="System.Collections" />
243+
<Reference Include="System.Collections.Concurrent" />
243244
<Reference Include="System.Collections.NonGeneric" />
244245
<Reference Include="System.Collections.Specialized" />
245246
<Reference Include="System.ComponentModel" />

src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/PropertyDescriptor.cs

+23-16
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections;
5+
using System.Collections.Concurrent;
6+
using System.Collections.Generic;
57
using System.Diagnostics.CodeAnalysis;
68
using System.Reflection;
9+
using System.Threading;
710

811
namespace System.ComponentModel
912
{
@@ -15,10 +18,11 @@ public abstract class PropertyDescriptor : MemberDescriptor
1518
internal const string PropertyDescriptorPropertyTypeMessage = "PropertyDescriptor's PropertyType cannot be statically discovered.";
1619

1720
private TypeConverter? _converter;
18-
private Hashtable? _valueChangedHandlers;
21+
private ConcurrentDictionary<object, EventHandler?>? _valueChangedHandlers;
1922
private object?[]? _editors;
2023
private Type[]? _editorTypes;
2124
private int _editorCount;
25+
private object? _syncObject;
2226

2327
/// <summary>
2428
/// Initializes a new instance of the <see cref='System.ComponentModel.PropertyDescriptor'/> class with the specified name and
@@ -48,6 +52,8 @@ protected PropertyDescriptor(MemberDescriptor descr, Attribute[]? attrs) : base(
4852
{
4953
}
5054

55+
private object SyncObject => LazyInitializer.EnsureInitialized(ref _syncObject);
56+
5157
/// <summary>
5258
/// When overridden in a derived class, gets the type of the
5359
/// component this property is bound to.
@@ -132,13 +138,11 @@ public virtual void AddValueChanged(object component, EventHandler handler)
132138
throw new ArgumentNullException(nameof(handler));
133139
}
134140

135-
if (_valueChangedHandlers == null)
141+
lock (SyncObject)
136142
{
137-
_valueChangedHandlers = new Hashtable();
143+
_valueChangedHandlers ??= new ConcurrentDictionary<object, EventHandler?>(concurrencyLevel: 1, capacity: 0);
144+
_valueChangedHandlers.AddOrUpdate(component, handler, (k, v) => (EventHandler?)Delegate.Combine(v, handler));
138145
}
139-
140-
EventHandler? h = (EventHandler?)_valueChangedHandlers[component];
141-
_valueChangedHandlers[component] = Delegate.Combine(h, handler);
142146
}
143147

144148
/// <summary>
@@ -392,7 +396,7 @@ protected virtual void OnValueChanged(object? component, EventArgs e)
392396
{
393397
if (component != null)
394398
{
395-
((EventHandler?)_valueChangedHandlers?[component])?.Invoke(component, e);
399+
_valueChangedHandlers?.GetValueOrDefault(component, defaultValue: null)?.Invoke(component, e);
396400
}
397401
}
398402

@@ -412,15 +416,18 @@ public virtual void RemoveValueChanged(object component, EventHandler handler)
412416

413417
if (_valueChangedHandlers != null)
414418
{
415-
EventHandler? h = (EventHandler?)_valueChangedHandlers[component];
416-
h = (EventHandler?)Delegate.Remove(h, handler);
417-
if (h != null)
418-
{
419-
_valueChangedHandlers[component] = h;
420-
}
421-
else
419+
lock (SyncObject)
422420
{
423-
_valueChangedHandlers.Remove(component);
421+
EventHandler? h = _valueChangedHandlers.GetValueOrDefault(component, defaultValue: null);
422+
h = (EventHandler?)Delegate.Remove(h, handler);
423+
if (h != null)
424+
{
425+
_valueChangedHandlers[component] = h;
426+
}
427+
else
428+
{
429+
_valueChangedHandlers.TryRemove(component, out EventHandler? _);
430+
}
424431
}
425432
}
426433
}
@@ -434,7 +441,7 @@ public virtual void RemoveValueChanged(object component, EventHandler handler)
434441
{
435442
if (component != null && _valueChangedHandlers != null)
436443
{
437-
return (EventHandler?)_valueChangedHandlers[component];
444+
return _valueChangedHandlers.GetValueOrDefault(component, defaultValue: null);
438445
}
439446
else
440447
{

src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs

+21-44
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Collections.Concurrent;
67
using System.ComponentModel.Design;
78
using System.Diagnostics;
89
using System.Diagnostics.CodeAnalysis;
@@ -23,10 +24,8 @@ namespace System.ComponentModel
2324
/// </summary>
2425
internal sealed partial class ReflectTypeDescriptionProvider : TypeDescriptionProvider
2526
{
26-
// Hastable of Type -> ReflectedTypeData. ReflectedTypeData contains all
27-
// of the type information we have gathered for a given type.
28-
//
29-
private Hashtable? _typeData;
27+
// ReflectedTypeData contains all of the type information we have gathered for a given type.
28+
private readonly ConcurrentDictionary<Type, ReflectedTypeData> _typeData = new ConcurrentDictionary<Type, ReflectedTypeData>();
3029

3130
// This is the signature we look for when creating types that are generic, but
3231
// want to know what type they are dealing with. Enums are a good example of this;
@@ -81,8 +80,6 @@ internal sealed partial class ReflectTypeDescriptionProvider : TypeDescriptionPr
8180

8281
internal static Guid ExtenderProviderKey { get; } = Guid.NewGuid();
8382

84-
85-
private static readonly object s_internalSyncObject = new object();
8683
/// <summary>
8784
/// Creates a new ReflectTypeDescriptionProvider. The type is the
8885
/// type we will obtain type information for.
@@ -234,7 +231,7 @@ internal static void AddEditorTable(Type editorBaseType, Hashtable table)
234231
// don't throw; RTM didn't so we can't do it either.
235232
}
236233

237-
lock (s_internalSyncObject)
234+
lock (TypeDescriptor.s_commonSyncObject)
238235
{
239236
Hashtable editorTables = EditorTables;
240237
if (!editorTables.ContainsKey(editorBaseType))
@@ -289,7 +286,6 @@ internal static void AddEditorTable(Type editorBaseType, Hashtable table)
289286
return obj ?? Activator.CreateInstance(objectType, args);
290287
}
291288

292-
293289
/// <summary>
294290
/// Helper method to create editors and type converters. This checks to see if the
295291
/// type implements a Type constructor, and if it does it invokes that ctor.
@@ -421,7 +417,7 @@ internal TypeConverter GetConverter([DynamicallyAccessedMembers(DynamicallyAcces
421417
//
422418
if (table == null)
423419
{
424-
lock (s_internalSyncObject)
420+
lock (TypeDescriptor.s_commonSyncObject)
425421
{
426422
table = editorTables[editorBaseType];
427423
if (table == null)
@@ -838,22 +834,11 @@ internal Type[] GetPopulatedTypes(Module module)
838834
{
839835
List<Type> typeList = new List<Type>();
840836

841-
lock (s_internalSyncObject)
837+
foreach (KeyValuePair<Type, ReflectedTypeData> kvp in _typeData)
842838
{
843-
Hashtable? typeData = _typeData;
844-
if (typeData != null)
839+
if (kvp.Key.Module == module && kvp.Value!.IsPopulated)
845840
{
846-
// Manual use of IDictionaryEnumerator instead of foreach to avoid DictionaryEntry box allocations.
847-
IDictionaryEnumerator e = typeData.GetEnumerator();
848-
while (e.MoveNext())
849-
{
850-
DictionaryEntry de = e.Entry;
851-
Type type = (Type)de.Key;
852-
if (type.Module == module && ((ReflectedTypeData)de.Value!).IsPopulated)
853-
{
854-
typeList.Add(type);
855-
}
856-
}
841+
typeList.Add(kvp.Key);
857842
}
858843
}
859844

@@ -898,31 +883,23 @@ public override Type GetReflectionType(
898883
/// </summary>
899884
private ReflectedTypeData? GetTypeData([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, bool createIfNeeded)
900885
{
901-
ReflectedTypeData? td = null;
902-
903-
if (_typeData != null)
886+
if (_typeData.TryGetValue(type, out ReflectedTypeData? td))
904887
{
905-
td = (ReflectedTypeData?)_typeData[type];
906-
if (td != null)
907-
{
908-
return td;
909-
}
888+
Debug.Assert(td != null);
889+
return td;
910890
}
911891

912-
lock (s_internalSyncObject)
892+
lock (TypeDescriptor.s_commonSyncObject)
913893
{
914-
if (_typeData != null)
894+
if (_typeData.TryGetValue(type, out td))
915895
{
916-
td = (ReflectedTypeData?)_typeData[type];
896+
Debug.Assert(td != null);
897+
return td;
917898
}
918899

919-
if (td == null && createIfNeeded)
900+
if (createIfNeeded)
920901
{
921902
td = new ReflectedTypeData(type);
922-
if (_typeData == null)
923-
{
924-
_typeData = new Hashtable();
925-
}
926903
_typeData[type] = td;
927904
}
928905
}
@@ -1010,7 +987,7 @@ internal static Attribute[] ReflectGetAttributes(Type type)
1010987
return attrs;
1011988
}
1012989

1013-
lock (s_internalSyncObject)
990+
lock (TypeDescriptor.s_commonSyncObject)
1014991
{
1015992
attrs = (Attribute[]?)attributeCache[type];
1016993
if (attrs == null)
@@ -1038,7 +1015,7 @@ internal static Attribute[] ReflectGetAttributes(MemberInfo member)
10381015
return attrs;
10391016
}
10401017

1041-
lock (s_internalSyncObject)
1018+
lock (TypeDescriptor.s_commonSyncObject)
10421019
{
10431020
attrs = (Attribute[]?)attributeCache[member];
10441021
if (attrs == null)
@@ -1067,7 +1044,7 @@ private static EventDescriptor[] ReflectGetEvents(
10671044
return events;
10681045
}
10691046

1070-
lock (s_internalSyncObject)
1047+
lock (TypeDescriptor.s_commonSyncObject)
10711048
{
10721049
events = (EventDescriptor[]?)eventCache[type];
10731050
if (events == null)
@@ -1164,7 +1141,7 @@ private static PropertyDescriptor[] ReflectGetExtendedProperties(IExtenderProvid
11641141
ReflectPropertyDescriptor[]? extendedProperties = (ReflectPropertyDescriptor[]?)extendedPropertyCache[providerType];
11651142
if (extendedProperties == null)
11661143
{
1167-
lock (s_internalSyncObject)
1144+
lock (TypeDescriptor.s_commonSyncObject)
11681145
{
11691146
extendedProperties = (ReflectPropertyDescriptor[]?)extendedPropertyCache[providerType];
11701147

@@ -1244,7 +1221,7 @@ private static PropertyDescriptor[] ReflectGetProperties(
12441221
return properties;
12451222
}
12461223

1247-
lock (s_internalSyncObject)
1224+
lock (TypeDescriptor.s_commonSyncObject)
12481225
{
12491226
properties = (PropertyDescriptor[]?)propertyCache[type];
12501227

0 commit comments

Comments
 (0)