Skip to content

Commit

Permalink
Merge pull request #559 from microsoft/fixThreadSafetyBug
Browse files Browse the repository at this point in the history
Fix thread-safety bug in MetadataIndex
  • Loading branch information
AArnott committed May 19, 2022
2 parents 0bfcfbb + 0bf1b52 commit a5f7c43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Microsoft.Windows.CsWin32/MetadataIndex.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO.MemoryMappedFiles;
Expand Down Expand Up @@ -43,7 +44,7 @@ internal class MetadataIndex

private readonly HashSet<string> releaseMethods = new HashSet<string>(StringComparer.Ordinal);

private readonly Dictionary<TypeReferenceHandle, TypeDefinitionHandle> refToDefCache = new();
private readonly ConcurrentDictionary<TypeReferenceHandle, TypeDefinitionHandle> refToDefCache = new();

/// <summary>
/// The set of names of typedef structs that represent handles where the handle has length of <see cref="IntPtr"/>
Expand Down Expand Up @@ -305,7 +306,7 @@ internal bool TryGetTypeDefHandle(MetadataReader reader, TypeReferenceHandle typ
}
}

this.refToDefCache.Add(typeRefHandle, typeDefHandle);
this.refToDefCache.TryAdd(typeRefHandle, typeDefHandle);
return !typeDefHandle.IsNil;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.Windows.CsWin32/SourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ private static string AssembleFullExceptionMessage(Exception ex)
inner = inner.InnerException;
}

sb.AppendLine();
sb.AppendLine(ex.ToString());

return sb.ToString();
}

Expand Down

0 comments on commit a5f7c43

Please sign in to comment.