Skip to content

Commit

Permalink
Core: Fix concurrent modification of single-threaded dict
Browse files Browse the repository at this point in the history
  • Loading branch information
SamboyCoding committed Nov 6, 2024
1 parent df352eb commit 14b0f05
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Cpp2IL.Core/Utils/AsmResolver/AsmResolverUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Cpp2IL.Core.Utils.AsmResolver;

public static class AsmResolverUtils
{
private static readonly Dictionary<string, TypeDefinition?> CachedTypeDefsByName = new();
private static readonly Dictionary<string, TypeSignature?> CachedTypeSignaturesByName = new();
private static readonly ConcurrentDictionary<string, TypeDefinition?> CachedTypeDefsByName = new();
private static readonly ConcurrentDictionary<string, TypeSignature?> CachedTypeSignaturesByName = new();
private static readonly ConcurrentDictionary<AssemblyDefinition, ReferenceImporter> ImportersByAssembly = new();

public static readonly ConcurrentDictionary<long, TypeDefinition> TypeDefsByIndex = new();
Expand Down Expand Up @@ -222,7 +222,13 @@ public static ITypeDefOrRef ImportReferenceFromIl2CppType(ModuleDefinition modul
&& string.Equals(t.Definition.FullName.Replace('/', '.'), name, StringComparison.OrdinalIgnoreCase);
});

return definedType?.GetExtraData<TypeDefinition>("AsmResolverType");
ret = definedType?.GetExtraData<TypeDefinition>("AsmResolverType");

if (ret == null)
return null;

CachedTypeDefsByName.TryAdd(key, ret);
return ret;
}

public static TypeSignature? TryLookupTypeSignatureByName(string? name, ReadOnlySpan<string> genericParameterNames = default)
Expand All @@ -238,7 +244,7 @@ public static ITypeDefOrRef ImportReferenceFromIl2CppType(ModuleDefinition modul
var result = InternalTryLookupTypeSignatureByName(name, genericParameterNames);

if (genericParameterNames.Length == 0)
CachedTypeSignaturesByName[key] = result;
CachedTypeSignaturesByName.TryAdd(key, result);

return result;
}
Expand Down

0 comments on commit 14b0f05

Please sign in to comment.