[DllImport(JitSupportLibrary)]
private extern static char* GetExceptionMessage(IntPtr obj);
- private readonly UnboxingMethodDescFactory _unboxingThunkFactory;
+ private static readonly UnboxingMethodDescFactory _unboxingThunkFactory = new UnboxingMethodDescFactory();
public static void Startup()
{
}
_unmanagedCallbacks = GetUnmanagedCallbacks(out _keepAlive);
-
- _unboxingThunkFactory = new UnboxingMethodDescFactory();
}
public TextWriter Log
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using Internal.TypeSystem;
#endif
}
- internal class UnboxingMethodDescFactory : Dictionary<MethodDesc, UnboxingMethodDesc>
+ internal class UnboxingMethodDescFactory : ConcurrentDictionary<MethodDesc, UnboxingMethodDesc>
{
- public UnboxingMethodDesc GetUnboxingMethod(MethodDesc method)
+ private Func<MethodDesc, UnboxingMethodDesc> _factoryDelegate;
+ private UnboxingMethodDesc CreateUnboxingMethod(MethodDesc method)
{
- if (!TryGetValue(method, out UnboxingMethodDesc result))
- {
- result = new UnboxingMethodDesc(method, this);
- Add(method, result);
- }
+ return new UnboxingMethodDesc(method, this);
+ }
- return result;
+ public UnboxingMethodDescFactory()
+ {
+ _factoryDelegate = CreateUnboxingMethod;
+ }
+
+ public UnboxingMethodDesc GetUnboxingMethod(MethodDesc method)
+ {
+ return GetOrAdd(method, _factoryDelegate);
}
}