ソースを参照

[corlib] Match closer ExecutionContextSwitcher methods

Marek Safar 10 年 前
コミット
c6299a9e0b

+ 1 - 1
external/referencesource

@@ -1 +1 @@
-Subproject commit 5e1cda3a267d139dbb6e5494bf77308fe5e5d70c
+Subproject commit 1b9933b838c86b93452a5a291a65d86655fd2daf

+ 57 - 38
mcs/class/corlib/System.Threading/ExecutionContext.cs

@@ -42,48 +42,14 @@ namespace System.Threading {
 	public sealed partial class ExecutionContext : ISerializable
            , IDisposable
 	{
-		internal struct Switcher
-		{
-			readonly ExecutionContext ec;
-			readonly LogicalCallContext _lcc;
-			readonly bool _suppressFlow;
-			readonly bool _capture;
-			readonly Dictionary<string, object> local_data;
-			readonly bool copy_on_write;
-
-			public Switcher (ExecutionContext ec)
-			{
-				this.ec = ec;
-				this._lcc = ec._lcc;
-				this._suppressFlow = ec._suppressFlow;
-				this._capture = ec._capture;
-				this.local_data = ec.local_data;
-				this.copy_on_write = ec.CopyOnWrite;
-			}
-
-			public bool IsEmpty {
-				get {
-					return ec == null;
-				}
-			}
-
-			public void Restore (ExecutionContext ec)
-			{
-				ec._lcc = this._lcc;
-				ec._suppressFlow = this._suppressFlow;
-				ec._capture = this._capture;
-				ec.local_data = this.local_data;
-				ec.CopyOnWrite = this.copy_on_write;
-			}
-		}
 
 #if !MOBILE
 		private SecurityContext _sc;
 #endif
-		private LogicalCallContext _lcc;
-		private bool _suppressFlow;
-		private bool _capture;
-		Dictionary<string, object> local_data;
+		internal LogicalCallContext _lcc;
+		internal bool _suppressFlow;
+		internal bool _capture;
+		internal Dictionary<string, object> local_data;
 
 		internal ExecutionContext ()
 		{
@@ -294,5 +260,58 @@ namespace System.Threading {
 
 			return current;
 		}
+
+		static internal void EstablishCopyOnWriteScope (Thread currentThread, bool knownNullWindowsIdentity, ref ExecutionContextSwitcher ecsw)
+		{
+			if (!currentThread.HasExecutionContext) {
+				ecsw = default (ExecutionContextSwitcher);
+			} else {
+				var _ec = currentThread.ExecutionContext;
+				ecsw = new ExecutionContextSwitcher (_ec);
+				_ec.CopyOnWrite = true;
+			}
+		}
+	}
+
+	internal struct ExecutionContextSwitcher
+	{
+		readonly ExecutionContext ec;
+		readonly LogicalCallContext _lcc;
+		readonly bool _suppressFlow;
+		readonly bool _capture;
+		readonly Dictionary<string, object> local_data;
+		readonly bool copy_on_write;
+
+		public ExecutionContextSwitcher (ExecutionContext ec)
+		{
+			this.ec = ec;
+			this._lcc = ec._lcc;
+			this._suppressFlow = ec._suppressFlow;
+			this._capture = ec._capture;
+			this.local_data = ec.local_data;
+			this.copy_on_write = ec.CopyOnWrite;
+		}
+
+		public bool IsEmpty {
+			get {
+				return ec == null;
+			}
+		}
+
+		public void Undo (Thread currentThread)
+		{
+			if (currentThread == null)
+				return;
+
+			if (ec != null) {
+				ec._lcc = this._lcc;
+				ec._suppressFlow = this._suppressFlow;
+				ec._capture = this._capture;
+				ec.local_data = this.local_data;
+				ec.CopyOnWrite = this.copy_on_write;
+			}
+
+			currentThread.ExecutionContext = ec;
+		}
 	}
 }

+ 0 - 20
mcs/class/corlib/System.Threading/Thread.cs

@@ -783,26 +783,6 @@ namespace System.Threading {
 			}
 		}
 
-		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 {
 			[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
 			get {