未验证 提交 c21f3712 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #19183 from sharwell/rm-lock

🧹 Remove unnecessary locking from GetOrComputeDescriptors
......@@ -219,34 +219,15 @@ public void ClearSymbolScopeTask(ISymbol symbol)
public ImmutableArray<DiagnosticDescriptor> GetOrComputeDescriptors(DiagnosticAnalyzer analyzer, AnalyzerExecutor analyzerExecutor)
{
lock (_gate)
if (!_lazyDescriptors.IsDefault)
{
if (!_lazyDescriptors.IsDefault)
{
return _lazyDescriptors;
}
return _lazyDescriptors;
}
// Otherwise, compute the value.
// We do so outside the lock statement as we are calling into user code, which may be a long running operation.
var descriptors = ComputeDescriptors(analyzer, analyzerExecutor);
lock (_gate)
{
// Check if another thread already stored the computed value.
if (!_lazyDescriptors.IsDefault)
{
// If so, we return the stored value.
descriptors = _lazyDescriptors;
}
else
{
// Otherwise, store the value computed here.
_lazyDescriptors = descriptors;
}
}
return descriptors;
ImmutableInterlocked.InterlockedInitialize(ref _lazyDescriptors, descriptors);
return _lazyDescriptors;
}
/// <summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册