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 16 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
/// <returns> /// <returns>
/// Returns a task that will make the parse result available. /// Returns a task that will make the parse result available.
/// </returns> /// </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) public static Task<ParseInformation> BeginParse(string fileName)
{ {
return GetFileEntry(fileName, true).BeginParse(null); return GetFileEntry(fileName, true).BeginParse(null);
@ -670,6 +677,13 @@ namespace ICSharpCode.SharpDevelop
/// <returns> /// <returns>
/// Returns a task that will make the parse result available. /// Returns a task that will make the parse result available.
/// </returns> /// </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) public static Task<ParseInformation> BeginParse(string fileName, ITextBuffer fileContent)
{ {
if (fileContent == null) if (fileContent == null)
@ -714,6 +728,13 @@ namespace ICSharpCode.SharpDevelop
/// Parses the current view content. /// Parses the current view content.
/// This method can only be called from the main thread. /// This method can only be called from the main thread.
/// </summary> /// </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() public static Task<ParseInformation> BeginParseCurrentViewContent()
{ {
WorkbenchSingleton.AssertMainThread(); WorkbenchSingleton.AssertMainThread();
@ -728,6 +749,13 @@ namespace ICSharpCode.SharpDevelop
/// Begins parsing the specified view content. /// Begins parsing the specified view content.
/// This method can only be called from the main thread. /// This method can only be called from the main thread.
/// </summary> /// </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) public static Task<ParseInformation> BeginParseViewContent(IViewContent viewContent)
{ {
if (viewContent == null) if (viewContent == null)

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

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

Loading…
Cancel
Save