Selaa lähdekoodia

2005-06-25 Gonzalo Paniagua Javier <[email protected]>

	* FAMWatcher.cs: make this really inactive when there are no events to
	process.


svn path=/trunk/mcs/; revision=46505
Gonzalo Paniagua Javier 20 vuotta sitten
vanhempi
sitoutus
157df963d5
2 muutettua tiedostoa jossa 95 lisäystä ja 91 poistoa
  1. 5 0
      mcs/class/System/System.IO/ChangeLog
  2. 90 91
      mcs/class/System/System.IO/FAMWatcher.cs

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

@@ -1,3 +1,8 @@
+2005-06-25 Gonzalo Paniagua Javier <[email protected]>
+
+	* FAMWatcher.cs: make this really inactive when there are no events to
+	process.
+
 2005-05-28 Gonzalo Paniagua Javier <[email protected]>
 
 	* FAMWatcher.cs: move the call to StartMonitoringDirectory out of any

+ 90 - 91
mcs/class/System/System.IO/FAMWatcher.cs

@@ -197,17 +197,26 @@ namespace System.IO {
 
 		void Monitor ()
 		{
+			string filename;
+			int code, request_number;
+
 			while (!stop) {
-				int haveEvents;
-				lock (this) {
-					haveEvents = FAMPending (ref conn);
-				}
+				int res = -1;
 
-				if (haveEvents > 0) {
-					ProcessEvents ();
-				} else {
-					Thread.Sleep (500);
+				try {
+					res = InternalFAMNextEvent (ref conn, out filename, out code, out request_number);
+				} catch (ThreadAbortException) {
+					Thread.ResetAbort ();
+					break;
 				}
+
+				if (res == 0)
+					continue;
+
+				if (res == -1)
+					break;
+
+				ProcessEvents (filename, code, request_number);
 			}
 
 			lock (this) {
@@ -221,98 +230,88 @@ namespace System.IO {
 						NotifyFilters.Size	|
 						NotifyFilters.LastWrite;
 
-		void ProcessEvents ()
+		void ProcessEvents (string filename, int code, int requestNumber)
 		{
 			ArrayList newdirs = null;
 			lock (this) {
-				do {
-					int code;
-					string filename;
-					int requestNumber;
-					FileSystemWatcher fsw;
-
-					if (InternalFAMNextEvent (ref conn, out filename,
-								  out code, out requestNumber) != 1)
-						return;
-
-					bool found = false;
-					switch ((FAMCodes) code) {
-					case FAMCodes.Changed:
-					case FAMCodes.Deleted:
-					case FAMCodes.Created:
-						found = requests.ContainsKey (requestNumber);
-						break;
-					case FAMCodes.Moved:
-					case FAMCodes.StartExecuting:
-					case FAMCodes.StopExecuting:
-					case FAMCodes.Acknowledge:
-					case FAMCodes.Exists:
-					case FAMCodes.EndExist:
-					default:
-						found = false;
-						break;
+				FileSystemWatcher fsw;
+				bool found = false;
+				switch ((FAMCodes) code) {
+				case FAMCodes.Changed:
+				case FAMCodes.Deleted:
+				case FAMCodes.Created:
+					found = requests.ContainsKey (requestNumber);
+					break;
+				case FAMCodes.Moved:
+				case FAMCodes.StartExecuting:
+				case FAMCodes.StopExecuting:
+				case FAMCodes.Acknowledge:
+				case FAMCodes.Exists:
+				case FAMCodes.EndExist:
+				default:
+					found = false;
+					break;
+				}
+
+				if (!found)
+					return;
+				
+				FAMData data = (FAMData) requests [requestNumber];
+				if (!data.Enabled)
+					return;
+
+				fsw = data.FSW;
+				NotifyFilters flt = fsw.NotifyFilter;
+				RenamedEventArgs renamed = null;
+				FileAction fa = 0;
+				if (code == (int) FAMCodes.Changed && (flt & changed) != 0)
+					fa = FileAction.Modified;
+				else if (code == (int) FAMCodes.Deleted)
+					fa = FileAction.Removed;
+				else if (code == (int) FAMCodes.Created)
+					fa = FileAction.Added;
+
+				if (fa == 0)
+					return;
+
+				if (fsw.IncludeSubdirectories) {
+					string full = fsw.FullPath;
+					string datadir = data.Directory;
+					if (datadir != full) {
+						string reldir = datadir.Substring (full.Length + 1);
+						datadir = Path.Combine (datadir, filename);
+						filename = Path.Combine (reldir, filename);
+					} else {
+						datadir = Path.Combine (fsw.FullPath, filename);
 					}
 
-					if (!found)
-						continue;
-					
-					FAMData data = (FAMData) requests [requestNumber];
-					if (!data.Enabled)
-						continue;
-
-					fsw = data.FSW;
-					NotifyFilters flt = fsw.NotifyFilter;
-					RenamedEventArgs renamed = null;
-					FileAction fa = 0;
-					if (code == (int) FAMCodes.Changed && (flt & changed) != 0)
-						fa = FileAction.Modified;
-					else if (code == (int) FAMCodes.Deleted)
-						fa = FileAction.Removed;
-					else if (code == (int) FAMCodes.Created)
-						fa = FileAction.Added;
-
-					if (fa == 0)
-						continue;
-
-					if (fsw.IncludeSubdirectories) {
-						string full = fsw.FullPath;
-						string datadir = data.Directory;
-						if (datadir != full) {
-							string reldir = datadir.Substring (full.Length + 1);
-							datadir = Path.Combine (datadir, filename);
-							filename = Path.Combine (reldir, filename);
-						} else {
-							datadir = Path.Combine (fsw.FullPath, filename);
-						}
-
-						if (fa == FileAction.Added && Directory.Exists (datadir)) {
-							if (newdirs == null)
-								newdirs = new ArrayList (4);
-
-							FAMData fd = new FAMData ();
-							fd.FSW = fsw;
-							fd.Directory = datadir;
-							fd.FileMask = fsw.MangledFilter;
-							fd.IncludeSubdirs = true;
-							fd.SubDirs = new Hashtable ();
-							fd.Enabled = true;
-							newdirs.Add (fd);
-							newdirs.Add (data);
-							requests [fd.Request.ReqNum] = fd;
-						}
+					if (fa == FileAction.Added && Directory.Exists (datadir)) {
+						if (newdirs == null)
+							newdirs = new ArrayList (4);
+
+						FAMData fd = new FAMData ();
+						fd.FSW = fsw;
+						fd.Directory = datadir;
+						fd.FileMask = fsw.MangledFilter;
+						fd.IncludeSubdirs = true;
+						fd.SubDirs = new Hashtable ();
+						fd.Enabled = true;
+						newdirs.Add (fd);
+						newdirs.Add (data);
+						requests [fd.Request.ReqNum] = fd;
 					}
+				}
 
-					if (filename != data.Directory && !fsw.Pattern.IsMatch (filename))
-						continue;
+				if (filename != data.Directory && !fsw.Pattern.IsMatch (filename))
+					return;
 
-					lock (fsw) {
-						fsw.DispatchEvents (fa, filename, ref renamed);
-						if (fsw.Waiting) {
-							fsw.Waiting = false;
-							System.Threading.Monitor.PulseAll (fsw);
-						}
+				lock (fsw) {
+					fsw.DispatchEvents (fa, filename, ref renamed);
+					if (fsw.Waiting) {
+						fsw.Waiting = false;
+						System.Threading.Monitor.PulseAll (fsw);
 					}
-				} while (FAMPending (ref conn) > 0);
+				}
 			}