Pārlūkot izejas kodu

2007-08-08 Marek Habersack <[email protected]>

	* SessionDictionary.cs: do not use lock (this), replace it
	with lock (this_object), where this_object is an instance
	variable. Prevents deadlocks in situation when external code locks
	on the class instance.
2007-08-08  Marek Habersack  <[email protected]>

	* WebConfigurationSettings.cs: do not use lock (this), replace it
	with lock (this_object), where this_object is an instance
	variable. Prevents deadlocks in situation when external code locks
	on the class instance.
2007-08-08  Marek Habersack  <[email protected]>

	* StaticSiteMapProvider.cs, HttpApplicationFactory.cs,
	HttpStaticObjectsCollection.cs, SiteMapProvider.cs,
	XmlSiteMapProvider.cs, HttpApplication.cs, CapabilitiesLoader.cs,
	TimeoutManager.cs: do not use lock (this), replace it with lock
	(this_object), where this_object is an instance	variable. Prevents
	deadlocks in situation when external code locks on the class
	instance.

svn path=/trunk/mcs/; revision=83648
Marek Habersack 18 gadi atpakaļ
vecāks
revīzija
2416d13727

+ 7 - 0
mcs/class/System.Web/System.Web.Configuration/ChangeLog

@@ -1,3 +1,10 @@
+2007-08-08  Marek Habersack  <[email protected]>
+
+	* WebConfigurationSettings.cs: do not use lock (this), replace it
+	with lock (this_object), where this_object is an instance
+	variable. Prevents deadlocks in situation when external code locks
+	on the class instance.
+
 2007-05-01  Marek Habersack  <[email protected]>
 
 	* HttpCapabilitiesBase.cs: move the User-Agent code to a separate

+ 6 - 3
mcs/class/System.Web/System.Web.Configuration/WebConfigurationSettings.cs

@@ -141,6 +141,8 @@ namespace System.Web.Configuration
 	//
 	class WebDefaultConfig : IConfigurationSystem
 	{
+		object this_lock = new object ();
+		
 #if TARGET_J2EE
 		static private WebDefaultConfig instance {
 			get {
@@ -263,7 +265,7 @@ namespace System.Web.Configuration
 			if (initCalled)
 				return;
 
-			lock (this) {
+			lock (this_lock) {
 				if (initCalled)
 					return;
 
@@ -372,6 +374,7 @@ namespace System.Web.Configuration
 
 	class ConfigurationData
 	{
+		object this_lock = new object ();
 		ConfigurationData parent;
 		Hashtable factories;
 		Hashtable pending;
@@ -391,7 +394,7 @@ namespace System.Web.Configuration
 
                 internal FileWatcherCache FileCache {
                         get {
-				lock (this) {
+				lock (this_lock) {
 					if (fileCache != null)
 						return fileCache;
 
@@ -659,7 +662,7 @@ namespace System.Web.Configuration
                         if (config != null)
                                 return config;
 
-			lock (this) {
+			lock (this_lock) {
 				config = GetConfigInternal (sectionName, context, useLoc);
 				this.FileCache [sectionName] = (config == null) ? emptyMark : config;
 			}

+ 7 - 0
mcs/class/System.Web/System.Web.SessionState/ChangeLog

@@ -1,3 +1,10 @@
+2007-08-08  Marek Habersack  <[email protected]>
+
+	* SessionDictionary.cs: do not use lock (this), replace it
+	with lock (this_object), where this_object is an instance
+	variable. Prevents deadlocks in situation when external code locks
+	on the class instance.
+
 2007-06-20  Marek Habersack  <[email protected]>
 
 	* SessionInProcHandler.cs: use HttpRuntime.InternalCache to keep

+ 18 - 16
mcs/class/System.Web/System.Web.SessionState/SessionDictionary.cs

@@ -35,6 +35,8 @@ namespace System.Web.SessionState {
 
 internal class SessionDictionary : NameObjectCollectionBase
 {
+	object this_lock = new object ();
+	
 	public SessionDictionary ()
 	{
 	}
@@ -53,14 +55,14 @@ internal class SessionDictionary : NameObjectCollectionBase
 	
 	internal void Clear ()
 	{
-		lock (this)
+		lock (this_lock)
 			BaseClear ();
 	}
 
 	internal string GetKey (int index)
 	{
 		string value;
-		lock (this)
+		lock (this_lock)
 			value = BaseGetKey (index);
 			
 		return value;
@@ -68,30 +70,30 @@ internal class SessionDictionary : NameObjectCollectionBase
 
 	internal void Remove (string s)
 	{
-		lock (this)
+		lock (this_lock)
 			BaseRemove (s);
 	}
 
 	internal void RemoveAt (int index)
 	{
-		lock (this)
+		lock (this_lock)
 			BaseRemoveAt (index);
 	}
 
 	internal void Serialize (BinaryWriter writer)
-	{
-		writer.Write (Count);
-		foreach (string key in base.Keys) {
-			writer.Write (key);
-			System.Web.Util.AltSerialization.Serialize (writer, BaseGet (key));
+	{
+		writer.Write (Count);
+		foreach (string key in base.Keys) {
+			writer.Write (key);
+			System.Web.Util.AltSerialization.Serialize (writer, BaseGet (key));
 		}
 	}
 
 	internal static SessionDictionary Deserialize (BinaryReader r)
 	{
-		SessionDictionary result = new SessionDictionary ();
-		for (int i = r.ReadInt32(); i > 0; i--)
-			result [r.ReadString ()] =
+		SessionDictionary result = new SessionDictionary ();
+		for (int i = r.ReadInt32(); i > 0; i--)
+			result [r.ReadString ()] =
 				System.Web.Util.AltSerialization.Deserialize (r);
 
 		return result;
@@ -101,14 +103,14 @@ internal class SessionDictionary : NameObjectCollectionBase
 	{
 		get {
 			object o;
-			lock (this)
+			lock (this_lock)
 				o = BaseGet (s);
 
 			return o;
 		}
 
 		set {
-			lock (this)
+			lock (this_lock)
 			{				 
 				object obj = BaseGet(s);
 				if ((obj == null) && (value == null))
@@ -122,13 +124,13 @@ internal class SessionDictionary : NameObjectCollectionBase
 	{
 		get {
 			object o;
-			lock (this)
+			lock (this_lock)
 				o = BaseGet (index);
 
 			return o;
 		}
 		set {
-			lock (this)
+			lock (this_lock)
 			{
 				object obj = BaseGet(index);
 				if ((obj == null) && (value == null))

+ 3 - 1
mcs/class/System.Web/System.Web/CapabilitiesLoader.cs

@@ -45,6 +45,8 @@ namespace System.Web
 	class BrowserData
 	{
 		static char [] wildchars = new char [] {'*', '?'};
+
+		object this_lock = new object ();
 		BrowserData parent;
 		string text;
 		string pattern;
@@ -148,7 +150,7 @@ namespace System.Web
 			if (pattern == null)
 				return expression.Length == 0;
 
-			lock (this) {
+			lock (this_lock) {
 				if (regex == null)
 #if TARGET_JVM
 					regex = java.util.regex.Pattern.compile (pattern);

+ 10 - 0
mcs/class/System.Web/System.Web/ChangeLog

@@ -1,3 +1,13 @@
+2007-08-08  Marek Habersack  <[email protected]>
+
+	* StaticSiteMapProvider.cs, HttpApplicationFactory.cs,
+	HttpStaticObjectsCollection.cs, SiteMapProvider.cs,
+	XmlSiteMapProvider.cs, HttpApplication.cs, CapabilitiesLoader.cs,
+	TimeoutManager.cs: do not use lock (this), replace it with lock
+	(this_object), where this_object is an instance	variable. Prevents
+	deadlocks in situation when external code locks on the class
+	instance.
+
 2007-08-05  Vladimir Krasnov  <[email protected]>
 
 	* HttpUtility.cs: performance refactoring, optimized UrlEncode

+ 3 - 1
mcs/class/System.Web/System.Web/HttpApplication.cs

@@ -87,6 +87,8 @@ namespace System.Web {
 	// attributes
 	[ToolboxItem(false)]
 	public class HttpApplication : IHttpAsyncHandler, IHttpHandler, IComponent, IDisposable {
+		object this_lock = new object();
+		
 		HttpContext context;
 		HttpSessionState session;
 		ISite isite;
@@ -164,7 +166,7 @@ namespace System.Web {
 		
 		internal void InitOnce (bool full_init)
 		{
-			lock (this) {
+			lock (this_lock) {
 				if (modcoll != null)
 					return;
 

+ 5 - 3
mcs/class/System.Web/System.Web/HttpApplicationFactory.cs

@@ -45,6 +45,8 @@ using System.CodeDom.Compiler;
 
 namespace System.Web {
 	class HttpApplicationFactory {
+		object this_lock = new object ();
+		
 		// Initialized in InitType
 #if TARGET_J2EE
 		static HttpApplicationFactory theFactory {
@@ -127,7 +129,7 @@ namespace System.Web {
 		
 		Hashtable GetApplicationTypeEvents (Type type)
 		{
-			lock (this) {
+			lock (this_lock) {
 				if (app_event_handlers != null)
 					return app_event_handlers;
 
@@ -147,7 +149,7 @@ namespace System.Web {
 
 		Hashtable GetApplicationTypeEvents (HttpApplication app)
 		{
-			lock (this) {
+			lock (this_lock) {
 				if (app_event_handlers != null)
 					return app_event_handlers;
 
@@ -353,7 +355,7 @@ namespace System.Web {
 		
 		void InitType (HttpContext context)
 		{
-			lock (this) {
+			lock (this_lock) {
 				if (!needs_init)
 					return;
 

+ 4 - 2
mcs/class/System.Web/System.Web/HttpStaticObjectsCollection.cs

@@ -33,9 +33,11 @@ namespace System.Web {
 		private Hashtable _Objects;
 
 		class StaticItem {
+			object this_lock = new object();
+			
 			Type type;
 			object instance;
-
+			
 			public StaticItem (Type type)
 			{
 				this.type = type;
@@ -48,7 +50,7 @@ namespace System.Web {
 			
 			public object Instance {
 				get {
-					lock (this) {
+					lock (this_lock) {
 						if (instance == null)
 							instance = Activator.CreateInstance (type);
 					}

+ 2 - 1
mcs/class/System.Web/System.Web/SiteMapProvider.cs

@@ -41,6 +41,7 @@ using System.Web.Configuration;
 
 namespace System.Web {
 	public abstract class SiteMapProvider : ProviderBase {
+		internal object this_lock = new object ();
 		
 		bool enableLocalization;
 		SiteMapProvider parentProvider;
@@ -229,7 +230,7 @@ namespace System.Web {
 		
 		public virtual SiteMapProvider RootProvider {
 			get {
-				lock (this) {
+				lock (this_lock) {
 					if (rootProviderCache == null) {
 						SiteMapProvider current = this;
 						while (current.ParentProvider != null)

+ 7 - 7
mcs/class/System.Web/System.Web/StaticSiteMapProvider.cs

@@ -51,7 +51,7 @@ namespace System.Web
 			if (node == null)
 				throw new ArgumentNullException ("node");
 			
-			lock (this) {
+			lock (this_lock) {
 				string url = node.Url;
 				if (url != null && url.Length > 0) {
 					url = MapUrl (url);
@@ -82,7 +82,7 @@ namespace System.Web
 		
 		Hashtable NodeToParent {
 			get {
-				lock (this) {
+				lock (this_lock) {
 					if (nodeToParent == null)
 						nodeToParent = new Hashtable ();
 				}
@@ -92,7 +92,7 @@ namespace System.Web
 		
 		Hashtable NodeToChildren {
 			get {
-				lock (this) {
+				lock (this_lock) {
 					if (nodeToChildren == null)
 						nodeToChildren = new Hashtable ();
 				}
@@ -102,7 +102,7 @@ namespace System.Web
 		
 		Hashtable UrlToNode {
 			get {
-				lock (this) {
+				lock (this_lock) {
 					if (urlToNode == null) {
 						urlToNode = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
 					}
@@ -113,7 +113,7 @@ namespace System.Web
 		
 		Hashtable KeyToNode {
 			get {
-				lock (this) {
+				lock (this_lock) {
 					if (keyToNode == null)
 						keyToNode = new Hashtable ();
 				}
@@ -123,7 +123,7 @@ namespace System.Web
 		
 		protected virtual void Clear ()
 		{
-			lock (this) {
+			lock (this_lock) {
 				if (urlToNode != null)
 					urlToNode.Clear ();
 				if (nodeToChildren != null)
@@ -194,7 +194,7 @@ namespace System.Web
 			if (node == null)
 				throw new ArgumentNullException("node");
 			
-			lock (this) {
+			lock (this_lock) {
 				SiteMapNode parent = (SiteMapNode) NodeToParent [node];
 				if (NodeToParent.Contains (node))
 					NodeToParent.Remove (node);

+ 6 - 4
mcs/class/System.Web/System.Web/TimeoutManager.cs

@@ -41,6 +41,8 @@ namespace System.Web
 	
 	class TimeoutManager
 	{
+		object this_lock = new object();
+		
 		Timer timer;
 		Hashtable contexts;
 
@@ -73,7 +75,7 @@ namespace System.Web
 				value = list;
 			}
 
-			lock (this) {
+			lock (this_lock) {
 				contexts [context] = value;
 			}
 		}
@@ -85,7 +87,7 @@ namespace System.Web
 				return null;
 
 			if (value is Thread) {
-				lock (this) {
+				lock (this_lock) {
 					contexts.Remove (context);
 				}
 				return (Thread) value;
@@ -99,7 +101,7 @@ namespace System.Web
 			}
 
 			if (list.Count == 0) {
-				lock (this) {
+				lock (this_lock) {
 					contexts.Remove (context);
 				}
 			}
@@ -116,7 +118,7 @@ namespace System.Web
 			DateTime now = DateTime.UtcNow;
 			ArrayList clist = new ArrayList ();
 
-			lock (this) { // The lock prevents Keys enumerator from being out of synch
+			lock (this_lock) { // The lock prevents Keys enumerator from being out of synch
 				clist.AddRange (contexts.Keys);
 			}
 

+ 3 - 1
mcs/class/System.Web/System.Web/XmlSiteMapProvider.cs

@@ -45,6 +45,8 @@ namespace System.Web
 	public class XmlSiteMapProvider : StaticSiteMapProvider, IDisposable
 	{
 		static readonly char [] seperators = { ';', ',' };
+
+		object this_lock = new object ();
 		bool building;
 		string file;
 		SiteMapNode root = null;
@@ -87,7 +89,7 @@ namespace System.Web
 			if (building)
 				return null;
 			
-			lock (this) {
+			lock (this_lock) {
 				try {
 					building = true;
 					if (root != null)