Skip to content

Commit

Permalink
Merge pull request #21641 from heejaechang/threadSafe
Browse files Browse the repository at this point in the history
make SupportedDiagnosticId for build error thread safe
  • Loading branch information
heejaechang authored Aug 24, 2017
2 parents 1f4221b + c21f729 commit a194462
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,26 +420,29 @@ public void Done()

public bool SupportedDiagnosticId(ProjectId projectId, string id)
{
if (_diagnosticIdMap.TryGetValue(projectId, out var ids))
lock (_diagnosticIdMap)
{
return ids.Contains(id);
}
if (_diagnosticIdMap.TryGetValue(projectId, out var ids))
{
return ids.Contains(id);
}

// set ids set
var map = new HashSet<string>();
_diagnosticIdMap.Add(projectId, map);
// set ids set
var map = new HashSet<string>();
_diagnosticIdMap.Add(projectId, map);

var project = _solution.GetProject(projectId);
if (project == null)
{
// projectId no longer exist, return false;
return false;
}
var project = _solution.GetProject(projectId);
if (project == null)
{
// projectId no longer exist, return false;
return false;
}

var descriptorMap = _owner._diagnosticService.GetDiagnosticDescriptors(project);
map.UnionWith(descriptorMap.Values.SelectMany(v => v.Select(d => d.Id)));
var descriptorMap = _owner._diagnosticService.GetDiagnosticDescriptors(project);
map.UnionWith(descriptorMap.Values.SelectMany(v => v.Select(d => d.Id)));

return map.Contains(id);
return map.Contains(id);
}
}

public ImmutableArray<DiagnosticData> GetBuildDiagnostics()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
End Using
End Sub

<Fact>
Public Sub TestExternalDiagnostics_SupportedDiagnosticId_Concurrent()
Using workspace = TestWorkspace.CreateCSharp(String.Empty)
Dim waiter = New Waiter()
Dim service = New TestDiagnosticAnalyzerService()
Dim source = New ExternalErrorDiagnosticUpdateSource(workspace, service, New MockDiagnosticUpdateSourceRegistrationService(), waiter)

Dim project = workspace.CurrentSolution.Projects.First()
source.OnSolutionBuild(Me, Shell.UIContextChangedEventArgs.From(True))

Parallel.For(0, 100, Sub(i As Integer) source.SupportedDiagnosticId(project.Id, "CS1002"))
End Using
End Sub

<Fact>
Public Async Function TestExternalDiagnostics_DuplicatedError() As Task
Using workspace = TestWorkspace.CreateCSharp(String.Empty)
Expand Down

0 comments on commit a194462

Please sign in to comment.