Skip to content

Commit 244d7e5

Browse files
committed
Go back to explicit lock usage
1 parent 41b3b34 commit 244d7e5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public sealed partial class RazorCodeDocument
2424
public RazorFileKind FileKind => ParserOptions.FileKind;
2525

2626
private readonly PropertyTable _properties = new();
27-
private readonly Lazy<RazorHtmlDocument> _lazyHtmlDocument;
27+
private readonly object _htmlDocumentLock = new();
2828

2929
private RazorCodeDocument(
3030
RazorSourceDocument source,
@@ -40,7 +40,6 @@ private RazorCodeDocument(
4040
CodeGenerationOptions = codeGenerationOptions ?? RazorCodeGenerationOptions.Default;
4141

4242
_properties = properties ?? new();
43-
_lazyHtmlDocument = new(() => CreateHtmlDocument());
4443
}
4544

4645
public static RazorCodeDocument Create(
@@ -178,17 +177,20 @@ internal void SetCSharpDocument(RazorCSharpDocument value)
178177
}
179178

180179
internal RazorHtmlDocument GetHtmlDocument()
181-
=> _lazyHtmlDocument.Value;
182-
183-
private RazorHtmlDocument CreateHtmlDocument()
184180
{
185181
if (_properties.HtmlDocument.TryGetValue(out var result))
186182
{
187183
return result;
188184
}
189185

190-
result = RazorHtmlWriter.GetHtmlDocument(this);
191-
_properties.HtmlDocument.SetValue(result);
186+
lock (_htmlDocumentLock)
187+
{
188+
if (!_properties.HtmlDocument.TryGetValue(out result))
189+
{
190+
result = RazorHtmlWriter.GetHtmlDocument(this);
191+
_properties.HtmlDocument.SetValue(result);
192+
}
193+
}
192194

193195
return result;
194196
}

0 commit comments

Comments
 (0)