提交 17fd0b68 编写于 作者: J Jason Malinowski

Remove some explicit locks and replace with assertions the lock is already held

These should only get called as a part of a larger operation that is
already holding the lock; we can assert that directly and then remove
the extra lock statements.
上级 21798af6
......@@ -435,7 +435,7 @@ private void OnBatchScopeDisposed()
foreach (var (path, properties) in _metadataReferencesAddedInBatch)
{
var projectReference = _workspace.TryCreateConvertedProjectReference(Id, path, properties);
var projectReference = _workspace.TryCreateConvertedProjectReference_NoLock(Id, path, properties);
if (projectReference != null)
{
......@@ -459,7 +459,7 @@ private void OnBatchScopeDisposed()
// Metadata reference removing...
foreach (var (path, properties) in _metadataReferencesRemovedInBatch)
{
var projectReference = _workspace.TryRemoveConvertedProjectReference(Id, path, properties);
var projectReference = _workspace.TryRemoveConvertedProjectReference_NoLock(Id, path, properties);
if (projectReference != null)
{
......@@ -778,7 +778,7 @@ public void AddMetadataReference(string fullPath, MetadataReferenceProperties pr
{
_workspace.ApplyChangeToWorkspace(w =>
{
var projectReference = _workspace.TryCreateConvertedProjectReference(Id, fullPath, properties);
var projectReference = _workspace.TryCreateConvertedProjectReference_NoLock(Id, fullPath, properties);
if (projectReference != null)
{
......@@ -841,7 +841,7 @@ public void RemoveMetadataReference(string fullPath, MetadataReferenceProperties
{
_workspace.ApplyChangeToWorkspace(w =>
{
var projectReference = _workspace.TryRemoveConvertedProjectReference(Id, fullPath, properties);
var projectReference = _workspace.TryRemoveConvertedProjectReference_NoLock(Id, fullPath, properties);
// If this was converted to a project reference, we have now recorded the removal -- let's remove it here too
if (projectReference != null)
......
......@@ -1699,51 +1699,53 @@ private void ConvertProjectReferencesToMetadataReferences_NoLock(ProjectId proje
SetSolutionAndRaiseWorkspaceChanged_NoLock(modifiedSolution, projectIdsChanged);
}
public ProjectReference? TryCreateConvertedProjectReference(ProjectId referencingProject, string path, MetadataReferenceProperties properties)
public ProjectReference? TryCreateConvertedProjectReference_NoLock(ProjectId referencingProject, string path, MetadataReferenceProperties properties)
{
lock (_gate)
// Any conversion to or from project references must be done under the global workspace lock,
// since that needs to be coordinated with updating all projects simultaneously.
Debug.Assert(Monitor.IsEntered(_gate));
if (_projectsByOutputPath.TryGetValue(path, out var ids) && ids.Distinct().Count() == 1)
{
if (_projectsByOutputPath.TryGetValue(path, out var ids) && ids.Distinct().Count() == 1)
{
var projectIdToReference = ids.First();
var projectIdToReference = ids.First();
if (CanConvertMetadataReferenceToProjectReference_NoLock(referencingProject, projectIdToReference))
{
var projectReference = new ProjectReference(
projectIdToReference,
aliases: properties.Aliases,
embedInteropTypes: properties.EmbedInteropTypes);
if (CanConvertMetadataReferenceToProjectReference_NoLock(referencingProject, projectIdToReference))
{
var projectReference = new ProjectReference(
projectIdToReference,
aliases: properties.Aliases,
embedInteropTypes: properties.EmbedInteropTypes);
GetReferenceInfo_NoLock(referencingProject).ConvertedProjectReferences.Add((path, projectReference));
GetReferenceInfo_NoLock(referencingProject).ConvertedProjectReferences.Add((path, projectReference));
return projectReference;
}
else
{
return null;
}
return projectReference;
}
else
{
return null;
}
}
else
{
return null;
}
}
public ProjectReference? TryRemoveConvertedProjectReference(ProjectId referencingProject, string path, MetadataReferenceProperties properties)
public ProjectReference? TryRemoveConvertedProjectReference_NoLock(ProjectId referencingProject, string path, MetadataReferenceProperties properties)
{
lock (_gate)
// Any conversion to or from project references must be done under the global workspace lock,
// since that needs to be coordinated with updating all projects simultaneously.
Debug.Assert(Monitor.IsEntered(_gate));
var projectReferenceInformation = GetReferenceInfo_NoLock(referencingProject);
foreach (var convertedProject in projectReferenceInformation.ConvertedProjectReferences)
{
var projectReferenceInformation = GetReferenceInfo_NoLock(referencingProject);
foreach (var convertedProject in projectReferenceInformation.ConvertedProjectReferences)
if (convertedProject.path == path &&
convertedProject.projectReference.EmbedInteropTypes == properties.EmbedInteropTypes &&
convertedProject.projectReference.Aliases.SequenceEqual(properties.Aliases))
{
if (convertedProject.path == path &&
convertedProject.projectReference.EmbedInteropTypes == properties.EmbedInteropTypes &&
convertedProject.projectReference.Aliases.SequenceEqual(properties.Aliases))
{
projectReferenceInformation.ConvertedProjectReferences.Remove(convertedProject);
return convertedProject.projectReference;
}
projectReferenceInformation.ConvertedProjectReferences.Remove(convertedProject);
return convertedProject.projectReference;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册