From 5467f54ba2cb8757e6ed73a566e10e7fac5f65d6 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 7 Jul 2009 14:17:59 +0000 Subject: [PATCH] Fixed thread-safety problem in SearchClassReturnType. Don't set 'Strict' to true when creating new Boo project. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4412 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Boo/BooBinding/Project/Src/BooProject.cs | 1 - .../Implementations/SearchClassReturnType.cs | 20 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs index 96f55227ec..fdc2770a52 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BooProject.cs @@ -71,7 +71,6 @@ namespace Grunwald.BooBinding PropertyStorageLocations.ConfigurationSpecific, false); SetProperty("Release", null, "DefineConstants", "TRACE", PropertyStorageLocations.ConfigurationSpecific, false); - SetProperty("Strict", "True"); } void AddReference(string assembly) diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs index 1fdbc70afd..765c10a37d 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SearchClassReturnType.cs @@ -57,7 +57,16 @@ namespace ICSharpCode.SharpDevelop.Dom } volatile IReturnType cachedBaseType; - int isSearching; // 0=false, 1=true + + //int isSearching; // 0=false, 1=true + + // Required to prevent stack overflow on inferrence cycles + // replaces old 'isSearching' flag which wasn't thread-safe + [ThreadStatic] static BusyManager _busyManager; + + static BusyManager busyManager { + get { return _busyManager ?? (_busyManager = new BusyManager()); } + } void ClearCachedBaseType() { @@ -69,9 +78,10 @@ namespace ICSharpCode.SharpDevelop.Dom IReturnType type = cachedBaseType; if (type != null) return type; - if (Interlocked.CompareExchange(ref isSearching, 1, 0) != 0) - return null; - try { + using (var l = busyManager.Enter(this)) { + // abort if called recursively on the same thread + if (!l.Success) + return null; SearchTypeRequest request = new SearchTypeRequest(name, typeParameterCount, declaringClass, caretLine, caretColumn); if (!lookForInnerClassesInDeclaringClass) { // skip looking for inner classes by adjusting the CurrentType for the lookup @@ -82,8 +92,6 @@ namespace ICSharpCode.SharpDevelop.Dom if (type != null) DomCache.RegisterForClear(ClearCachedBaseType); return type; - } finally { - isSearching = 0; } } }