Fix comments
[mono.git] / mcs / class / corlib / System.Threading / CompressedStack.cs
index 41294062a0b5389ce95e8b2bf822f256174cde74..0e79ce5779791fa138e808e87634484624a5f8af 100644 (file)
@@ -37,12 +37,8 @@ using System.Security.Permissions;
 
 namespace System.Threading {
 
-#if NET_2_0
        [Serializable]
        public sealed class CompressedStack : ISerializable {
-#else
-       public class CompressedStack {
-#endif
                private ArrayList _list;
 
                internal CompressedStack (int length)
@@ -57,38 +53,29 @@ namespace System.Threading {
                                _list = (ArrayList) cs._list.Clone ();
                }
 
-#if NET_2_0
                [ComVisibleAttribute (false)]
-               public
-#else
-               internal
-#endif
-               CompressedStack CreateCopy ()
+               public CompressedStack CreateCopy ()
                {
                        return new CompressedStack (this);
                }
 
-#if NET_2_0
-               public
-#else
-               internal
-#endif
-               static CompressedStack Capture ()
+               public static CompressedStack Capture ()
                {
                        CompressedStack cs = new CompressedStack (0);
                        cs._list = SecurityFrame.GetStack (1);
-                       return cs;
-               }
 
-#if NET_2_0
-               [MonoTODO ("incomplete")]
-               [ReflectionPermission (SecurityAction.Demand, MemberAccess = true)]
-               public void GetObjectData (SerializationInfo info, StreamingContext context)
-               {
-                       if (info == null)
-                               throw new ArgumentNullException ("info");
+                       // include any current CompressedStack inside the new Capture
+                       CompressedStack currentCs = Thread.CurrentThread.GetCompressedStack ();
+                       if (currentCs != null) {
+                               for (int i=0; i < currentCs._list.Count; i++)
+                                       cs._list.Add (currentCs._list [i]);
+                       }
+                       return cs;
                }
 
+               // 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")]
                static public CompressedStack GetCompressedStack ()
@@ -96,7 +83,25 @@ namespace System.Threading {
                        // Note: CompressedStack.GetCompressedStack doesn't return null
                        // like Thread.CurrentThread.GetCompressedStack if no compressed
                        // stack is present.
-                       return new CompressedStack (Thread.CurrentThread.GetCompressedStack ());
+                       CompressedStack cs = Thread.CurrentThread.GetCompressedStack ();
+                       if (cs == null) {
+                               cs = CompressedStack.Capture ();
+                       } else {
+                               // 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 ();
+                               for (int i=0; i < newstack._list.Count; i++)
+                                       cs._list.Add (newstack._list [i]);
+                       }
+                       return cs;
+               }
+
+               [MonoTODO ("incomplete")]
+               [ReflectionPermission (SecurityAction.Demand, MemberAccess = true)]
+               public void GetObjectData (SerializationInfo info, StreamingContext context)
+               {
+                       if (info == null)
+                               throw new ArgumentNullException ("info");
                }
 
                [SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
@@ -117,9 +122,8 @@ namespace System.Threading {
                                        t.SetCompressedStack (original);
                        }
                }
-#endif
-               // internal stuff
 
+               // internal stuff
                internal bool Equals (CompressedStack cs)
                {
                        if (IsEmpty ())