ソースを参照

[corlib] Small part of thread from reference sources

Marek Safar 10 年 前
コミット
02fc6c1433

+ 1 - 1
external/referencesource

@@ -1 +1 @@
-Subproject commit 5ba8f8ccf5d991028f17d0bb1bd7dc07cd365a1e
+Subproject commit b8813958c3630d1b06d2a34d8d3b74bf3db79a38

+ 0 - 9
mcs/class/corlib/ReferenceSources/ExecutionContext.cs

@@ -44,13 +44,4 @@ namespace System.Threading
 			}
 		}
 	}
-
-	[Serializable]
-	internal enum StackCrawlMark
-	{
-		LookForMe = 0,
-		LookForMyCaller = 1,
-		LookForMyCallersCaller = 2,
-		LookForThread = 3
-	}
 }

+ 8 - 6
mcs/class/corlib/System.Threading/CompressedStack.cs

@@ -65,7 +65,7 @@ namespace System.Threading {
 			cs._list = SecurityFrame.GetStack (1);
 
 			// include any current CompressedStack inside the new Capture
-			CompressedStack currentCs = Thread.CurrentThread.GetCompressedStack ();
+			CompressedStack currentCs = Thread.CurrentThread.ExecutionContext.SecurityContext.CompressedStack;
 			if (currentCs != null) {
 				for (int i=0; i < currentCs._list.Count; i++)
 					cs._list.Add (currentCs._list [i]);
@@ -82,10 +82,12 @@ namespace System.Threading {
 			// Note: CompressedStack.GetCompressedStack doesn't return null
 			// like Thread.CurrentThread.GetCompressedStack if no compressed
 			// stack is present.
-			CompressedStack cs = Thread.CurrentThread.GetCompressedStack ();
-			if (cs == null) {
+
+            CompressedStack cs = Thread.CurrentThread.ExecutionContext.SecurityContext.CompressedStack;
+			if (cs == null || cs.IsEmpty ()) {
 				cs = CompressedStack.Capture ();
 			} else {
+				cs = cs.CreateCopy ();
 				// merge the existing compressed stack (from a previous Thread) with the current
 				// Thread stack so we can assign "all of it" to yet another Thread
 				CompressedStack newstack = CompressedStack.Capture ();
@@ -112,13 +114,13 @@ namespace System.Threading {
 			Thread t = Thread.CurrentThread;
 			CompressedStack original = null;
 			try {
-				original = t.GetCompressedStack (); 
-				t.SetCompressedStack (compressedStack);
+				original = t.ExecutionContext.SecurityContext.CompressedStack; 
+				t.ExecutionContext.SecurityContext.CompressedStack = compressedStack;
 				callback (state);
 			}
 			finally {
 				if (original != null)
-					t.SetCompressedStack (original);
+					t.ExecutionContext.SecurityContext.CompressedStack = original;
 			}
 		}
 

+ 12 - 76
mcs/class/corlib/System.Threading/Thread.cs

@@ -110,19 +110,12 @@ namespace System.Threading {
 		}
 	}
 
-	[ClassInterface (ClassInterfaceType.None)]
-	[ComVisible (true)]
-	[ComDefaultInterface (typeof (_Thread))]
 	[StructLayout (LayoutKind.Sequential)]
-#if MOBILE
-	public sealed class Thread : CriticalFinalizerObject {
-#else
-	public sealed class Thread : CriticalFinalizerObject, _Thread {
-#endif
+	public sealed partial class Thread {
 #pragma warning disable 414		
 		#region Sync with metadata/object-internals.h
 		private InternalThread internal_thread;
-		object start_obj;
+		object m_ThreadStartArg;
 		private ExecutionContext ec_to_set;
 		#endregion
 #pragma warning restore 414
@@ -154,7 +147,7 @@ namespace System.Threading {
 		static internal CultureInfo default_ui_culture;
 
 		// can be both a ThreadStart and a ParameterizedThreadStart
-		private MulticastDelegate threadstart;
+		private MulticastDelegate m_Delegate;
 		//private string thread_name=null;
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -432,7 +425,7 @@ namespace System.Threading {
 			if(start==null) {
 				throw new ArgumentNullException("Null ThreadStart");
 			}
-			threadstart=start;
+			m_Delegate=start;
 		}
 
 		private Thread (InternalThread it) {
@@ -690,10 +683,10 @@ namespace System.Threading {
 		{
 			current_thread = this;
 
-			if (threadstart is ThreadStart) {
-				((ThreadStart) threadstart) ();
+			if (m_Delegate is ThreadStart) {
+				((ThreadStart) m_Delegate) ();
 			} else {
-				((ParameterizedThreadStart) threadstart) (start_obj);
+				((ParameterizedThreadStart) m_Delegate) (m_ThreadStartArg);
 			}
 		}
 
@@ -817,11 +810,8 @@ namespace System.Threading {
 		[MethodImplAttribute (MethodImplOptions.InternalCall)]
 		extern static int SystemMaxStackStize ();
 
-		static int CheckStackSize (int maxStackSize)
+		static int GetProcessDefaultStackSize (int maxStackSize)
 		{
-			if (maxStackSize < 0)
-				throw new ArgumentOutOfRangeException ("less than zero", "maxStackSize");
-
 			if (maxStackSize < 131072) // make sure stack is at least 128k big
 				return 131072;
 
@@ -834,30 +824,10 @@ namespace System.Threading {
 			return Math.Min (maxStackSize, SystemMaxStackStize ());
 		}
 
-		public Thread (ThreadStart start, int maxStackSize)
-		{
-			if (start == null)
-				throw new ArgumentNullException ("start");
-
-			threadstart = start;
-			Internal.stack_size = CheckStackSize (maxStackSize);;
-		}
-
-		public Thread (ParameterizedThreadStart start)
+		void SetStart (MulticastDelegate start, int maxStackSize)
 		{
-			if (start == null)
-				throw new ArgumentNullException ("start");
-
-			threadstart = start;
-		}
-
-		public Thread (ParameterizedThreadStart start, int maxStackSize)
-		{
-			if (start == null)
-				throw new ArgumentNullException ("start");
-
-			threadstart = start;
-			Internal.stack_size = CheckStackSize (maxStackSize);
+			m_Delegate = start;
+			Internal.stack_size = maxStackSize;
 		}
 
 		public ExecutionContext ExecutionContext {
@@ -962,44 +932,10 @@ namespace System.Threading {
 
 		public void Start (object parameter)
 		{
-			start_obj = parameter;
+			m_ThreadStartArg = parameter;
 			Start ();
 		}
 
-		// NOTE: This method doesn't show in the class library status page because
-		// it cannot be "found" with the StrongNameIdentityPermission for ECMA key.
-		// But it's there!
-		[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
-		[StrongNameIdentityPermission (SecurityAction.LinkDemand, PublicKey="00000000000000000400000000000000")]
-		[Obsolete ("see CompressedStack class")]
-		public CompressedStack GetCompressedStack ()
-		{
-#if MOBILE
-			throw new NotSupportedException ();
-#else			
-			// Note: returns null if no CompressedStack has been set.
-			// However CompressedStack.GetCompressedStack returns an 
-			// (empty?) CompressedStack instance.
-			CompressedStack cs = ExecutionContext.SecurityContext.CompressedStack;
-			return ((cs == null) || cs.IsEmpty ()) ? null : cs.CreateCopy ();
-#endif
-		}
-
-		// NOTE: This method doesn't show in the class library status page because
-		// it cannot be "found" with the StrongNameIdentityPermission for ECMA key.
-		// But it's there!
-		[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
-		[StrongNameIdentityPermission (SecurityAction.LinkDemand, PublicKey="00000000000000000400000000000000")]
-		[Obsolete ("see CompressedStack class")]
-		public void SetCompressedStack (CompressedStack stack)
-		{
-#if MOBILE
-			throw new NotSupportedException ();
-#else
-			ExecutionContext.SecurityContext.CompressedStack = stack;
-#endif
-		}
-
 #if !MOBILE
 		void _Thread.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
 		{

+ 1 - 2
mcs/class/corlib/Test/System.Threading/CompressedStackTest.cs

@@ -55,7 +55,6 @@ namespace MonoTests.System.Threading {
 		public void SetUp ()
 		{
 			success = false;
-			Thread.CurrentThread.SetCompressedStack (null);
 		}
 
 		[Test]
@@ -135,7 +134,7 @@ namespace MonoTests.System.Threading {
 		{
 			// this is because Thread.CurrentThread.GetCompressedStack () returns null for an empty
 			// compressed stack while CompressedStack.GetCompressedStack () return "something" empty ;-)
-			CompressedStack.Run (Thread.CurrentThread.GetCompressedStack (), new ContextCallback (Callback), true);
+			CompressedStack.Run (null, new ContextCallback (Callback), true);
 		}
 	}
 }

+ 1 - 0
mcs/class/corlib/corlib.dll.sources

@@ -1540,6 +1540,7 @@ ReferenceSources/SharedStatics.cs
 ../../../external/referencesource/mscorlib/system/threading/SpinLock.cs
 ../../../external/referencesource/mscorlib/system/threading/SpinWait.cs
 ../../../external/referencesource/mscorlib/system/threading/synchronizationlockexception.cs
+../../../external/referencesource/mscorlib/system/threading/thread.cs
 ../../../external/referencesource/mscorlib/system/threading/threadabortexception.cs
 ../../../external/referencesource/mscorlib/system/threading/threadinterruptedexception.cs
 ../../../external/referencesource/mscorlib/system/threading/threadpriority.cs