Browse Source

fixed deadlock in ContextActionsService; added thread safety remarks to BeginParse* methods of ParserService

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6396 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 15 years ago
parent
commit
017af12002
  1. 28
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  2. 8
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs

28
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -658,6 +658,13 @@ namespace ICSharpCode.SharpDevelop @@ -658,6 +658,13 @@ namespace ICSharpCode.SharpDevelop
/// <returns>
/// Returns a task that will make the parse result available.
/// </returns>
/// <remarks>
/// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task&lt;ParseInformation&gt;)
/// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any
/// thread the parser might be waiting for (especially the main thread).
///
/// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread.
/// </remarks>
public static Task<ParseInformation> BeginParse(string fileName)
{
return GetFileEntry(fileName, true).BeginParse(null);
@ -670,6 +677,13 @@ namespace ICSharpCode.SharpDevelop @@ -670,6 +677,13 @@ namespace ICSharpCode.SharpDevelop
/// <returns>
/// Returns a task that will make the parse result available.
/// </returns>
/// <remarks>
/// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task&lt;ParseInformation&gt;)
/// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any
/// thread the parser might be waiting for (especially the main thread).
///
/// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread.
/// </remarks>
public static Task<ParseInformation> BeginParse(string fileName, ITextBuffer fileContent)
{
if (fileContent == null)
@ -714,6 +728,13 @@ namespace ICSharpCode.SharpDevelop @@ -714,6 +728,13 @@ namespace ICSharpCode.SharpDevelop
/// Parses the current view content.
/// This method can only be called from the main thread.
/// </summary>
/// <remarks>
/// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task&lt;ParseInformation&gt;)
/// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any
/// thread the parser might be waiting for (especially the main thread).
///
/// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread.
/// </remarks>
public static Task<ParseInformation> BeginParseCurrentViewContent()
{
WorkbenchSingleton.AssertMainThread();
@ -728,6 +749,13 @@ namespace ICSharpCode.SharpDevelop @@ -728,6 +749,13 @@ namespace ICSharpCode.SharpDevelop
/// Begins parsing the specified view content.
/// This method can only be called from the main thread.
/// </summary>
/// <remarks>
/// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task&lt;ParseInformation&gt;)
/// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any
/// thread the parser might be waiting for (especially the main thread).
///
/// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread.
/// </remarks>
public static Task<ParseInformation> BeginParseViewContent(IViewContent viewContent)
{
if (viewContent == null)

8
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs

@ -41,8 +41,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -41,8 +41,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{
if (ParserService.LoadSolutionProjectsThreadRunning)
yield break;
var parseTask = ParserService.BeginParseCurrentViewContent();
parseTask.Wait();
ParserService.ParseCurrentViewContent();
// DO NOT USE Wait on the main thread!
// causes deadlocks!
//parseTask.Wait();
var sw = new Stopwatch(); sw.Start();
var editorContext = new EditorContext(editor);
@ -55,7 +57,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -55,7 +57,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
}
}
ICSharpCode.Core.LoggingService.Debug(string.Format("Context actions elapsed {0}ms ({1}ms in EditorContext)",
sw.ElapsedMilliseconds, elapsedEditorContextMs));
sw.ElapsedMilliseconds, elapsedEditorContextMs));
}
}
}

Loading…
Cancel
Save