diff options
author | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-07-02 13:20:07 +0300 |
---|---|---|
committer | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-07-02 13:47:44 +0300 |
commit | 624f9da8a0259ace95011b2e158b140ec7464954 (patch) | |
tree | a7b24effe980d35001fec72270ac60a9a6a9add8 /main/src/core/MonoDevelop.Core | |
parent | c60593e956b8a77992f60343931528b8ebd56392 (diff) |
[Projects] Fix concurrent access to FileNestingService
The providers are initialized on demand, so in solutions with several
projects, that load each project on a separate Task, we were getting race
conditions on the NestingRulesProvider's initialization, so make sure
they are initialized only once and not called until they are fully loaded.
Diffstat (limited to 'main/src/core/MonoDevelop.Core')
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs | 2 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs | 25 |
2 files changed, 15 insertions, 12 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs index ae7da7da54..13aecfa2ee 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/FileNestingService.cs @@ -44,7 +44,7 @@ namespace MonoDevelop.Projects.FileNesting { var pr = args.ExtensionObject as NestingRulesProvider; if (pr != null) { - if (args.Change == ExtensionChange.Add) { + if (args.Change == ExtensionChange.Add && !rulesProviders.Contains (pr)) { rulesProviders = rulesProviders.Add (pr); } else { rulesProviders = rulesProviders.Remove (pr); diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs index 307c11dafa..1222b193eb 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.FileNesting/NestingRulesProvider.cs @@ -46,6 +46,7 @@ namespace MonoDevelop.Projects.FileNesting const string TokenNameAdd = "add"; List<NestingRule> nestingRules; + readonly object loadingLock = new object (); public NestingRulesProvider () { @@ -122,18 +123,20 @@ namespace MonoDevelop.Projects.FileNesting public FilePath GetParentFile (Project project, FilePath inputFile) { - if (nestingRules == null) { - // Create the list here, so that we don't get this path called - // again and again for every file in the solution if something - // goes wrong when loading the file. - nestingRules = new List<NestingRule> (); - - if (!File.Exists (SourceFile)) { - return null; - } + lock (loadingLock) { + if (nestingRules == null) { + // Create the list here, so that we don't get this path called + // again and again for every file in the solution if something + // goes wrong when loading the file. + nestingRules = new List<NestingRule> (); + + if (!File.Exists (SourceFile)) { + return null; + } - if (!LoadFromFile (this)) { - return null; + if (!LoadFromFile (this)) { + return null; + } } } |