[corlib] Small part of thread from reference sources
authorMarek Safar <marek.safar@gmail.com>
Tue, 19 May 2015 09:43:50 +0000 (11:43 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 19 May 2015 09:44:30 +0000 (11:44 +0200)
external/referencesource
mcs/class/corlib/ReferenceSources/ExecutionContext.cs
mcs/class/corlib/System.Threading/CompressedStack.cs
mcs/class/corlib/System.Threading/Thread.cs
mcs/class/corlib/Test/System.Threading/CompressedStackTest.cs
mcs/class/corlib/corlib.dll.sources

index 5ba8f8ccf5d991028f17d0bb1bd7dc07cd365a1e..b8813958c3630d1b06d2a34d8d3b74bf3db79a38 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 5ba8f8ccf5d991028f17d0bb1bd7dc07cd365a1e
+Subproject commit b8813958c3630d1b06d2a34d8d3b74bf3db79a38
index 0e79dba87d526275d5600c481379af2b230d2567..ec9230ffc3caa6cb6fce868973e2e7da54091da2 100644 (file)
@@ -44,13 +44,4 @@ namespace System.Threading
                        }
                }
        }
-
-       [Serializable]
-       internal enum StackCrawlMark
-       {
-               LookForMe = 0,
-               LookForMyCaller = 1,
-               LookForMyCallersCaller = 2,
-               LookForThread = 3
-       }
 }
\ No newline at end of file
index e440ba068b70b52d7a9cc3dcca3d9ea42cf4c733..b8a1535e0d7c75565baee70a6c7f3daa7e81dff3 100644 (file)
@@ -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;
                        }
                }
 
index a104619cf12e7ac2ff7fdf542c44054a86cdf833..6bcb53a60581a649587a9e6e0b91dc59c0fe136f 100644 (file)
@@ -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)
                {
index 7cf9c39e5a4932eabe291fe54b0aa940d0978084..0b88c3f585e5d6f0b3946300431059ca67a375a1 100644 (file)
@@ -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);
                }
        }
 }
index e36f21f3c910781c3a10bd962a64f525caf526f1..2a03392d713edf670855fb1897c140f946d90010 100644 (file)
@@ -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