Skip to content

Commit

Permalink
Merge branch 'saudi/fix-registry-duplicates' into 'main'
Browse files Browse the repository at this point in the history
fix duplicate avoidance in PlatformRegistry's implementation instances

See merge request Sharpmake/sharpmake!555
  • Loading branch information
jspelletier committed Sep 16, 2024
2 parents 675e07e + 687c5e4 commit 25d80ec
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions Sharpmake/PlatformRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public int GetHashCode(PlatformImplementation obj)

private static readonly ConcurrentDictionary<PlatformImplementation, object> s_implementations = new ConcurrentDictionary<PlatformImplementation, object>(new PlatformImplementationComparer());
private static readonly ConcurrentDictionary<Type, object> s_defaultImplementations = new ConcurrentDictionary<Type, object>();
private static readonly ConcurrentDictionary<object, bool> s_implementationInstances = new ConcurrentDictionary<object, bool>(); // Value is dummy
private static readonly ConcurrentDictionary<Type, object> s_implementationInstances = new ConcurrentDictionary<Type, object>();
private static readonly ConcurrentDictionary<Assembly, bool> s_parsedAssemblies = new ConcurrentDictionary<Assembly, bool>(); // Value is dummy

static PlatformRegistry()
Expand Down Expand Up @@ -499,26 +499,7 @@ private static void EnsureUniquePlatformImplementations(IEnumerable<PlatformImpl

private static object GetImplementationInstance(Type implType)
{
var result = s_implementationInstances.SingleOrDefault(obj => obj.GetType().AssemblyQualifiedName == implType.AssemblyQualifiedName);
object instance = null;
if (result.Key == null)
{
try
{
instance = Activator.CreateInstance(implType);
s_implementationInstances.TryAdd(instance, false);
}
catch (Exception ex)
{
throw new PlatformImplementationCreationException(implType, ex);
}
}
else
{
instance = result.Key;
}

return instance;
return s_implementationInstances.GetOrAdd(implType, t => Activator.CreateInstance(t));
}

private static void RegisterImplementationImpl(Platform platform, Type ifaceType, object implementation)
Expand Down

0 comments on commit 25d80ec

Please sign in to comment.