Browse Source

Fixed race condition in XmlFoldParser that could cause parser threads to get stuck in an infinite loop.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5646 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 15 years ago
parent
commit
7329ed2eb4
  1. 24
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFoldParser.cs
  2. 3
      src/AddIns/Misc/PInvokeAddIn/Project/PInvokeAddIn.csproj
  3. 11
      src/Main/Base/Project/Src/Project/IParser.cs

24
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlFoldParser.cs

@ -76,17 +76,23 @@ namespace ICSharpCode.XmlEditor @@ -76,17 +76,23 @@ namespace ICSharpCode.XmlEditor
public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent)
{
try {
CreateCompilationUnit(projectContent, fileName);
GetFolds(fileContent.CreateReader());
AddFoldsToCompilationUnit(unit, folds);
} catch (Exception) {
ICompilationUnit existingUnit = FindPreviouslyParsedCompilationUnit(projectContent, fileName);
if (existingUnit != null) {
return existingUnit;
// SharpDevelop may call IParser.Parse in parallel. This will be done on the same IParser instance
// if there are two parallel parse requests for the same file. Parser implementations must be thread-safe.
// In XmlFoldParser, we do this by simply using a big lock per IParser instance.
lock (this) {
try {
CreateCompilationUnit(projectContent, fileName);
GetFolds(fileContent.CreateReader());
AddFoldsToCompilationUnit(unit, folds);
} catch (XmlException) {
ICompilationUnit existingUnit = FindPreviouslyParsedCompilationUnit(projectContent, fileName);
if (existingUnit != null) {
return existingUnit;
}
}
return unit;
}
return unit;
}
void CreateCompilationUnit(IProjectContent projectContent, string fileName)

3
src/AddIns/Misc/PInvokeAddIn/Project/PInvokeAddIn.csproj

@ -53,9 +53,6 @@ @@ -53,9 +53,6 @@
<None Include="signatures.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="signatures.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="PInvoke.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

11
src/Main/Base/Project/Src/Project/IParser.cs

@ -41,6 +41,17 @@ namespace ICSharpCode.SharpDevelop.Project @@ -41,6 +41,17 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary>
bool CanParse(IProject project);
/// <summary>
/// Parses a file.
/// </summary>
/// <param name="projectContent">The parent project of the file.</param>
/// <param name="fileName">The name of the file being parsed.</param>
/// <param name="fileContent">The content of the file.</param>
/// <returns>The compilation unit representing the parse results.</returns>
/// <remarks>
/// SharpDevelop may call IParser.Parse in parallel. This will be done on the same IParser instance
/// if there are two parallel parse requests for the same file. Parser implementations must be thread-safe.
/// </remarks>
ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent);
IResolver CreateResolver();

Loading…
Cancel
Save