Ver Fonte

2005-05-28 Gonzalo Paniagua Javier <[email protected]>

	* FAMWatcher.cs: move the call to StartMonitoringDirectory out of any
	locks. Before, for a high amount of subdirectories (~500) it hanged
	after filling the write buffer of FAM socket. Fixes bug #74398.


svn path=/trunk/mcs/; revision=45131
Gonzalo Paniagua Javier há 20 anos atrás
pai
commit
bea2c4b94f

+ 6 - 0
mcs/class/System/System.IO/ChangeLog

@@ -1,3 +1,9 @@
+2005-05-28 Gonzalo Paniagua Javier <[email protected]>
+
+	* FAMWatcher.cs: move the call to StartMonitoringDirectory out of any
+	locks. Before, for a high amount of subdirectories (~500) it hanged
+	after filling the write buffer of FAM socket. Fixes bug #74398.
+
 2005-04-05  Lluis Sanchez Gual  <[email protected]>
 
 	* FAMWatcher.cs: Fix cast exception when disposing watchers.

+ 21 - 10
mcs/class/System/System.IO/FAMWatcher.cs

@@ -131,8 +131,8 @@ namespace System.IO {
 					data.SubDirs = new Hashtable ();
 
 				data.Enabled = true;
+				StartMonitoringDirectory (data);
 				lock (this) {
-					StartMonitoringDirectory (data);
 					watches [fsw] = data;
 					requests [data.Request.ReqNum] = data;
 					stop = false;
@@ -223,6 +223,7 @@ namespace System.IO {
 
 		void ProcessEvents ()
 		{
+			ArrayList newdirs = null;
 			lock (this) {
 				do {
 					int code;
@@ -285,6 +286,9 @@ namespace System.IO {
 						}
 
 						if (fa == FileAction.Added && Directory.Exists (datadir)) {
+							if (newdirs == null)
+								newdirs = new ArrayList (4);
+
 							FAMData fd = new FAMData ();
 							fd.FSW = fsw;
 							fd.Directory = datadir;
@@ -292,15 +296,8 @@ namespace System.IO {
 							fd.IncludeSubdirs = true;
 							fd.SubDirs = new Hashtable ();
 							fd.Enabled = true;
-
-							lock (instance) {
-								StartMonitoringDirectory (fd);
-							}
-
-							lock (data) {
-								data.SubDirs [datadir] = fd;
-							}
-
+							newdirs.Add (fd);
+							newdirs.Add (data);
 							requests [fd.Request.ReqNum] = fd;
 						}
 					}
@@ -317,6 +314,20 @@ namespace System.IO {
 					}
 				} while (FAMPending (ref conn) > 0);
 			}
+
+
+			if (newdirs != null) {
+				int count = newdirs.Count;
+				for (int n = 0; n < count; n++) {
+					FAMData newdir = (FAMData) newdirs [n];
+					FAMData parent = (FAMData) newdirs [n + 1];
+					StartMonitoringDirectory (newdir);
+					lock (parent) {
+						parent.SubDirs [newdir.Directory] = newdir;
+					}
+				}
+				newdirs.Clear ();
+			}
 		}
 
 		~FAMWatcher ()