Bläddra i källkod

2002-12-10 Dick Porter <[email protected]>

	* Monitor.cs:
	* Thread.cs:
	* ThreadPool.cs:
	* Timer.cs:
	* WaitHandle.cs: Use TotalMilliseconds to convert a TimeSpan to
	ms, not Milliseconds.

svn path=/trunk/mcs/; revision=9533
Dick Porter 23 år sedan
förälder
incheckning
21374e28f0

+ 9 - 0
mcs/class/corlib/System.Threading/ChangeLog

@@ -1,3 +1,12 @@
+2002-12-10  Dick Porter  <[email protected]>
+
+	* Monitor.cs:
+	* Thread.cs:
+	* ThreadPool.cs:
+	* Timer.cs:
+	* WaitHandle.cs: Use TotalMilliseconds to convert a TimeSpan to
+	ms, not Milliseconds.
+
 2002-12-07  Martin Baulig  <[email protected]>
 
 	* Timer.cs: Make it actually work; now it no longer sets your

+ 12 - 7
mcs/class/corlib/System.Threading/Monitor.cs

@@ -134,17 +134,18 @@ namespace System.Threading
 
 			// LAMESPEC: should throw an exception when ms<0, but
 			// Timeout.Infinite is -1
-			if(timeout.Milliseconds == Timeout.Infinite) {
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			if(ms == Timeout.Infinite) {
 				Enter(obj);
 				return(true);
 			}
 
-			if(timeout.Milliseconds < 0 ||
-			   timeout.Milliseconds > Int32.MaxValue) {
+			if(ms < 0 || ms > Int32.MaxValue) {
 				throw new ArgumentOutOfRangeException("timeout out of range");
 			}
 			
-			return(Monitor_try_enter(obj, timeout.Milliseconds));
+			return(Monitor_try_enter(obj, ms));
 		}
 
 		// Waits for a signal on object 'obj' with maximum
@@ -181,14 +182,16 @@ namespace System.Threading
 				throw new ArgumentNullException("Object is null");
 			}
 			// LAMESPEC: says to throw ArgumentException too
-			if(timeout.Milliseconds < 0 || timeout.Milliseconds > Int32.MaxValue) {
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			if(ms < 0 || ms > Int32.MaxValue) {
 				throw new ArgumentOutOfRangeException("timeout out of range");
 			}
 			if(Monitor_test_synchronised(obj)==false) {
 				throw new SynchronizationLockException("Object is not synchronised");
 			}
 
-			return(Monitor_wait(obj, timeout.Milliseconds));
+			return(Monitor_wait(obj, ms));
 		}
 
 		[MonoTODO]
@@ -207,7 +210,9 @@ namespace System.Threading
 				throw new ArgumentNullException("Object is null");
 			}
 			// LAMESPEC: says to throw ArgumentException too
-			if(timeout.Milliseconds < 0 || timeout.Milliseconds > Int32.MaxValue) {
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			if(ms < 0 || ms > Int32.MaxValue) {
 				throw new ArgumentOutOfRangeException("timeout out of range");
 			}
 			

+ 8 - 5
mcs/class/corlib/System.Threading/Thread.cs

@@ -166,14 +166,16 @@ namespace System.Threading
 
 		public static void Sleep(TimeSpan timeout) {
 			// LAMESPEC: says to throw ArgumentException too
-			if(timeout.Milliseconds < 0 || timeout.Milliseconds > Int32.MaxValue) {
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			if(ms < 0 || ms > Int32.MaxValue) {
 				throw new ArgumentOutOfRangeException("Timeout out of range");
 			}
 
 			Thread thread=CurrentThread;
 				
 			thread.set_state(ThreadState.WaitSleepJoin);
-			Sleep_internal(timeout.Milliseconds);
+			Sleep_internal(ms);
 			thread.clr_state(ThreadState.WaitSleepJoin);
 		}
 
@@ -359,7 +361,9 @@ namespace System.Threading
 
 		public bool Join(TimeSpan timeout) {
 			// LAMESPEC: says to throw ArgumentException too
-			if(timeout.Milliseconds < 0 || timeout.Milliseconds > Int32.MaxValue) {
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			if(ms < 0 || ms > Int32.MaxValue) {
 				throw new ArgumentOutOfRangeException("timeout out of range");
 			}
 			if((state & ThreadState.Unstarted) != 0) {
@@ -369,8 +373,7 @@ namespace System.Threading
 			Thread thread=CurrentThread;
 
 			thread.set_state(ThreadState.WaitSleepJoin);
-			bool ret=Join_internal(timeout.Milliseconds,
-					       system_thread_handle);
+			bool ret=Join_internal(ms, system_thread_handle);
 			thread.clr_state(ThreadState.WaitSleepJoin);
 
 			return(ret);

+ 4 - 2
mcs/class/corlib/System.Threading/ThreadPool.cs

@@ -207,10 +207,12 @@ namespace System.Threading
 		[MonoTODO]
 		public static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callback, object state, TimeSpan timeout, bool executeOnlyOnce) {
 			// LAMESPEC: I assume it means "timeout" when it says "millisecondsTimeOutInterval"
-			if (timeout.Milliseconds < -1) {
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			if (ms < -1) {
 				throw new ArgumentOutOfRangeException("timeout < -1");
 			}
-			if (timeout.Milliseconds > Int32.MaxValue) {
+			if (ms > Int32.MaxValue) {
 				throw new NotSupportedException("timeout too large");
 			}
 

+ 2 - 2
mcs/class/corlib/System.Threading/Timer.cs

@@ -153,7 +153,7 @@ namespace System.Threading
 		}
 
 		public Timer (TimerCallback callback, object state, TimeSpan dueTime, TimeSpan period)
-			: this (callback, state, dueTime.Milliseconds, period.Milliseconds)
+			: this (callback, state, Convert.ToInt32(dueTime.TotalMilliseconds), Convert.ToInt32(period.TotalMilliseconds))
 		{
 		}
 
@@ -201,7 +201,7 @@ namespace System.Threading
 
 		public bool Change (TimeSpan dueTime, TimeSpan period)
 		{
-			return Change (dueTime.Milliseconds, period.Milliseconds);
+			return Change (Convert.ToInt32(dueTime.TotalMilliseconds), Convert.ToInt32(period.TotalMilliseconds));
 		}
 
 		[CLSCompliant(false)]

+ 11 - 13
mcs/class/corlib/System.Threading/WaitHandle.cs

@@ -48,8 +48,9 @@ namespace System.Threading
 		public static bool WaitAll(WaitHandle[] waitHandles,
 					   TimeSpan timeout,
 					   bool exitContext) {
-			if(timeout.Milliseconds < 0 ||
-			   timeout.Milliseconds > Int32.MaxValue) {
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			if(ms < 0 || ms > Int32.MaxValue) {
 				throw new ArgumentOutOfRangeException("Timeout out of range");
 			}
 			if(waitHandles.Length>64) {
@@ -61,9 +62,7 @@ namespace System.Threading
 				}
 			}
 			
-			return(WaitAll_internal(waitHandles,
-						timeout.Milliseconds,
-						exitContext));
+			return(WaitAll_internal(waitHandles, ms, exitContext));
 		}
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -103,8 +102,9 @@ namespace System.Threading
 
 		public static int WaitAny(WaitHandle[] waitHandles,
 					  TimeSpan timeout, bool exitContext) {
-			if(timeout.Milliseconds < 0 ||
-			   timeout.Milliseconds > Int32.MaxValue) {
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			if(ms < 0 || ms > Int32.MaxValue) {
 				throw new ArgumentOutOfRangeException("Timeout out of range");
 			}
 			if(waitHandles.Length>64) {
@@ -116,9 +116,7 @@ namespace System.Threading
 				}
 			}
 			
-			return(WaitAny_internal(waitHandles,
-						timeout.Milliseconds,
-						exitContext));
+			return(WaitAny_internal(waitHandles, ms, exitContext));
 		}
 
 		[MonoTODO]
@@ -160,9 +158,9 @@ namespace System.Threading
 		}
 
 		public virtual bool WaitOne(TimeSpan timeout, bool exitContext) {
-			return(WaitOne_internal(os_handle,
-						timeout.Milliseconds,
-						exitContext));
+			int ms=Convert.ToInt32(timeout.TotalMilliseconds);
+			
+			return(WaitOne_internal(os_handle, ms, exitContext));
 		}
 
 		protected static readonly IntPtr InvalidHandle;