Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@ -38,11 +38,44 @@ using System.Collections.Generic;
namespace System.Threading {
[Serializable]
public sealed class ExecutionContext : ISerializable
#if NET_4_0
, IDisposable
#endif
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
@ -57,15 +90,20 @@ namespace System.Threading {
private ExecutionContext (ExecutionContext ec)
{
CloneData (ec);
_suppressFlow = ec._suppressFlow;
_capture = true;
}
void CloneData (ExecutionContext ec)
{
#if !MOBILE
if (ec._sc != null)
_sc = new SecurityContext (ec._sc);
#endif
if (ec._lcc != null)
_lcc = (LogicalCallContext) ec._lcc.Clone ();
_suppressFlow = ec._suppressFlow;
_capture = true;
}
[MonoTODO]
@ -81,7 +119,11 @@ namespace System.Threading {
internal static ExecutionContext Capture (bool captureSyncContext, bool nullOnEmpty)
{
ExecutionContext ec = Current;
var thread = Thread.CurrentThread;
if (nullOnEmpty && !thread.HasExecutionContext)
return null;
var ec = thread.ExecutionContext;
if (ec.FlowSuppressed)
return null;
@ -108,7 +150,6 @@ namespace System.Threading {
return new ExecutionContext (this);
}
#if NET_4_0
public void Dispose ()
{
#if !MOBILE
@ -116,7 +157,6 @@ namespace System.Threading {
_sc.Dispose ();
#endif
}
#endif
[MonoTODO]
[ReflectionPermission (SecurityAction.Demand, MemberAccess = true)]
@ -167,6 +207,8 @@ namespace System.Threading {
set { _suppressFlow = value; }
}
internal bool CopyOnWrite { get; set; }
public static bool IsFlowSuppressed ()
{
return Current.FlowSuppressed;
@ -180,6 +222,11 @@ namespace System.Threading {
ec.FlowSuppressed = false;
}
internal static void Run(ExecutionContext executionContext, ContextCallback callback, Object state, bool preserveSyncCtx)
{
Run (executionContext, callback, state);
}
[SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
public static void Run (ExecutionContext executionContext, ContextCallback callback, object state)
@ -232,5 +279,16 @@ namespace System.Threading {
return Thread.CurrentThread.ExecutionContext;
}
}
internal static ExecutionContext GetCurrentWritable ()
{
var current = Thread.CurrentThread.ExecutionContext;
if (current.CopyOnWrite) {
current.CopyOnWrite = false;
current.CloneData (current);
}
return current;
}
}
}
}