Browse Source

r7442@daniel-notebook (orig r3404): daniel | 2008-08-17 17:23:23 +0200

Make MessageViewCategory creation thread-safe.


git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3414 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
bc4d77b564
  1. 3
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs
  2. 2
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs
  3. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs
  4. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs
  5. 8
      src/AddIns/Misc/CodeCoverage/Project/Src/RunTestWithCodeCoverageCommand.cs
  6. 12
      src/AddIns/Misc/SubversionAddIn/Project/Src/SvnMessageView.cs
  7. 3
      src/AddIns/Misc/UnitTesting/Src/RunTestCommands.cs
  8. 26
      src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/MessageViewCategory.cs
  9. 2
      src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs
  10. 10
      src/Main/Base/Project/Src/Project/CustomTool.cs
  11. 4
      src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs

3
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs

@ -100,8 +100,7 @@ namespace ICSharpCode.PythonBinding @@ -100,8 +100,7 @@ namespace ICSharpCode.PythonBinding
static MessageViewCategory PythonMessageViewCategory {
get {
if (categorySingleton == null) {
categorySingleton = new MessageViewCategory("Python");
CompilerMessageView.Instance.AddCategory(categorySingleton);
MessageViewCategory.Create(ref categorySingleton, "Python");
}
return categorySingleton;
}

2
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs

@ -303,7 +303,7 @@ namespace ICSharpCode.WixBinding @@ -303,7 +303,7 @@ namespace ICSharpCode.WixBinding
public static SharpDevelopSideBar SetupDialogControlsToolBox {
get {
Debug.Assert(WorkbenchSingleton.InvokeRequired == false);
WorkbenchSingleton.AssertMainThread();
if (setupDialogControlsToolBox == null) {
setupDialogControlsToolBox = new SharpDevelopSideBar();
setupDialogControlsToolBox.Tabs.Add(SetupDialogControlsSideTab.CreateSideTab());

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -25,7 +25,7 @@ namespace ICSharpCode.WpfDesign.AddIn
public static WpfToolbox Instance {
get {
Debug.Assert(WorkbenchSingleton.InvokeRequired == false);
WorkbenchSingleton.AssertMainThread();
if (instance == null) {
instance = new WpfToolbox();
}

4
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs

@ -804,9 +804,7 @@ namespace ICSharpCode.XmlEditor @@ -804,9 +804,7 @@ namespace ICSharpCode.XmlEditor
MessageViewCategory Category {
get {
if (category == null) {
category = new MessageViewCategory(CategoryName);
CompilerMessageView cmv = (CompilerMessageView)WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).PadContent;
cmv.AddCategory(category);
MessageViewCategory.Create(ref category, CategoryName);
}
return category;

8
src/AddIns/Misc/CodeCoverage/Project/Src/RunTestWithCodeCoverageCommand.cs

@ -72,14 +72,12 @@ namespace ICSharpCode.CodeCoverage @@ -72,14 +72,12 @@ namespace ICSharpCode.CodeCoverage
MessageViewCategory Category {
get {
if (category == null) {
category = new MessageViewCategory(StringParser.Parse("${res:ICSharpCode.UnitTesting.CodeCoverage}"));
CompilerMessageView cmv = (CompilerMessageView)WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).PadContent;
cmv.AddCategory(category);
MessageViewCategory.Create(ref category, "CodeCoverage", StringParser.Parse("${res:ICSharpCode.UnitTesting.CodeCoverage}"));
}
return category;
}
}
void SetPartCoverRunnerProperties(UnitTestApplicationStartHelper helper)
{
string partCoverOutputDirectory = GetPartCoverOutputDirectory(helper.Project);
@ -89,7 +87,7 @@ namespace ICSharpCode.CodeCoverage @@ -89,7 +87,7 @@ namespace ICSharpCode.CodeCoverage
// no include or exclude regular expressions have been
// set for this project. Note that the CodeCoverageResults
// will ignore any type that has no source code available
// for it even though the type may be in the Part Cover
// for it even though the type may be in the Part Cover
// results file.
if (settings.Include.Count + settings.Exclude.Count == 0) {
settings.Include.Add("[*]*");

12
src/AddIns/Misc/SubversionAddIn/Project/Src/SvnMessageView.cs

@ -13,23 +13,27 @@ using ICSharpCode.SharpDevelop.Gui; @@ -13,23 +13,27 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.Svn
{
/// <summary>
/// Description of SvnMessageView.
/// Output pad category for subversion.
/// </summary>
public static class SvnMessageView
{
static MessageViewCategory category;
/// <summary>
/// Gets the subversion message view category.
/// </summary>
public static MessageViewCategory Category {
get {
if (category == null) {
category = new MessageViewCategory("Subversion");
CompilerMessageView compilerMessageView = (CompilerMessageView)WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).PadContent;
compilerMessageView.AddCategory(category);
MessageViewCategory.Create(ref category, "Subversion");
}
return category;
}
}
/// <summary>
/// Appends a line to the svn message view.
/// </summary>
public static void AppendLine(string text)
{
Category.AppendLine(text);

3
src/AddIns/Misc/UnitTesting/Src/RunTestCommands.cs

@ -87,8 +87,7 @@ namespace ICSharpCode.UnitTesting @@ -87,8 +87,7 @@ namespace ICSharpCode.UnitTesting
public static MessageViewCategory TestRunnerCategory {
get {
if (testRunnerCategory == null) {
testRunnerCategory = new MessageViewCategory("${res:ICSharpCode.NUnitPad.NUnitPadContent.PadName}");
CompilerMessageView.Instance.AddCategory(testRunnerCategory);
MessageViewCategory.Create(ref testRunnerCategory, "UnitTesting", "${res:ICSharpCode.NUnitPad.NUnitPadContent.PadName}");
}
return testRunnerCategory;
}

26
src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/MessageViewCategory.cs

@ -50,6 +50,32 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -50,6 +50,32 @@ namespace ICSharpCode.SharpDevelop.Gui
this.displayCategory = displayCategory;
}
/// <summary>
/// Creates a new MessageViewCategory with the specified category
/// and adds it to the CompilerMessageView pad.
/// This method is thread-safe and works correctly even if called multiple times for the same
/// thread; only one messageViewCategory will be created.
/// </summary>
public static void Create(ref MessageViewCategory messageViewCategory, string category)
{
Create(ref messageViewCategory, category, category);
}
/// <summary>
/// Creates a new MessageViewCategory with the specified category
/// and adds it to the CompilerMessageView pad.
/// This method is thread-safe and works correctly even if called concurrently for the same
/// category; only one messageViewCategory will be created.
/// </summary>
public static void Create(ref MessageViewCategory messageViewCategory, string category, string displayCategory)
{
MessageViewCategory newMessageViewCategory = new MessageViewCategory(category, displayCategory);
if (System.Threading.Interlocked.CompareExchange(ref messageViewCategory, newMessageViewCategory, null) == null) {
// this thread was successful creating the category, so add it
CompilerMessageView.Instance.AddCategory(newMessageViewCategory);
}
}
public void AppendLine(string text)
{
AppendText(text + Environment.NewLine);

2
src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs

@ -206,7 +206,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -206,7 +206,7 @@ namespace ICSharpCode.SharpDevelop.Gui
/// <summary>
/// Throws an exception if the current thread is not the main thread.
/// </summary>
internal static void AssertMainThread()
public static void AssertMainThread()
{
if (InvokeRequired) {
throw new InvalidOperationException("This operation can be called on the main thread only.");

10
src/Main/Base/Project/Src/Project/CustomTool.cs

@ -84,18 +84,12 @@ namespace ICSharpCode.SharpDevelop.Project @@ -84,18 +84,12 @@ namespace ICSharpCode.SharpDevelop.Project
});
}
static object lockObject = new object();
static volatile MessageViewCategory customToolMessageView;
static MessageViewCategory customToolMessageView;
internal static MessageViewCategory StaticMessageView {
get {
if (customToolMessageView == null) {
lock (lockObject) {
if (customToolMessageView == null) {
customToolMessageView = new MessageViewCategory("Custom Tool");
CompilerMessageView.Instance.AddCategory(customToolMessageView);
}
}
MessageViewCategory.Create(ref customToolMessageView, "Custom Tool");
}
return customToolMessageView;
}

4
src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs

@ -135,9 +135,7 @@ namespace ICSharpCode.SharpDevelop.Debugging @@ -135,9 +135,7 @@ namespace ICSharpCode.SharpDevelop.Debugging
static void EnsureDebugCategory()
{
if (debugCategory == null) {
debugCategory = new MessageViewCategory("Debug", "${res:MainWindow.Windows.OutputWindow.DebugCategory}");
CompilerMessageView compilerMessageView = (CompilerMessageView)WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).PadContent;
compilerMessageView.AddCategory(debugCategory);
MessageViewCategory.Create(ref debugCategory, "Debug", "${res:MainWindow.Windows.OutputWindow.DebugCategory}");
}
}

Loading…
Cancel
Save