Merge pull request #1632 from alexanderkyte/bug24118
[mono.git] / mcs / class / corlib / System.Threading / Thread.cs
index d4a8d167a34246acea4db11c40161a6f6391add7..4be83d2cd58c9807089f4146144911f26f85ccce 100644 (file)
@@ -406,12 +406,10 @@ namespace System.Threading {
                        ResetAbort_internal ();
                }
 
-#if NET_4_0
                [HostProtectionAttribute (SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
                public extern static bool Yield ();
-#endif
 
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -587,11 +585,12 @@ namespace System.Threading {
 
                public ThreadPriority Priority {
                        get {
-                               return(ThreadPriority.Lowest);
+                               return (ThreadPriority)GetPriority (Internal);
                        }
                        
                        set {
-                               // FIXME: Implement setter.
+                               // FIXME: This doesn't do anything yet
+                               SetPriority (Internal, (int)value);
                        }
                }
 
@@ -604,6 +603,12 @@ namespace System.Threading {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern static void Abort_internal (InternalThread thread, object stateInfo);
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               private extern static int GetPriority (InternalThread thread);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               private extern static void SetPriority (InternalThread thread, int priority);
+
                [SecurityPermission (SecurityAction.Demand, ControlThread=true)]
                public void Abort () 
                {
@@ -696,8 +701,7 @@ namespace System.Threading {
 
                public void Start() {
                        // propagate informations from the original thread to the new thread
-                       if (!ExecutionContext.IsFlowSuppressed ())
-                               ec_to_set = ExecutionContext.Capture ();
+                       ec_to_set = ExecutionContext.Capture (false, true);
                        Internal._serialized_principal = CurrentThread.Internal._serialized_principal;
 
                        // Thread_internal creates and starts the new thread, 
@@ -858,7 +862,6 @@ namespace System.Threading {
                        Internal.stack_size = CheckStackSize (maxStackSize);
                }
 
-               [MonoTODO ("limited to CompressedStack support")]
                public ExecutionContext ExecutionContext {
                        [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
                        get {
@@ -866,6 +869,35 @@ namespace System.Threading {
                                        _ec = new ExecutionContext ();
                                return _ec;
                        }
+                       internal set {
+                               _ec = value;
+                       }
+               }
+
+               internal bool HasExecutionContext {
+                       get {
+                               return _ec != null;
+                       }
+               }
+
+               internal void BranchExecutionContext (out ExecutionContext.Switcher switcher)
+               {
+                       if (_ec == null) {
+                               switcher =  new ExecutionContext.Switcher ();
+                       } else {
+                               switcher = new ExecutionContext.Switcher (_ec);
+                               _ec.CopyOnWrite = true;
+                       }
+               }
+
+               internal void RestoreExecutionContext (ref ExecutionContext.Switcher switcher)
+               {
+                       if (switcher.IsEmpty) {
+                               _ec = null;
+                               return;
+                       }
+
+                       switcher.Restore (_ec);
                }
 
                public int ManagedThreadId {
@@ -992,5 +1024,10 @@ namespace System.Threading {
                        throw new NotImplementedException ();
                }
 #endif
+
+               internal CultureInfo GetCurrentUICultureNoAppX ()
+               {
+                       return CultureInfo.CurrentUICulture;
+               }
        }
 }