Author: spouliot
Date: 2005-04-28 08:13:22 -0400 (Thu, 28 Apr 2005)
New Revision: 43715
Modified:
trunk/mcs/class/corlib/System.Threading/AsyncFlowControl.cs
trunk/mcs/class/corlib/System.Threading/ChangeLog
trunk/mcs/class/corlib/System.Threading/CompressedStack.cs
trunk/mcs/class/corlib/System.Threading/ContextCallback.cs
trunk/mcs/class/corlib/System.Threading/ExecutionContext.cs
trunk/mcs/class/corlib/System.Threading/HostExecutionContext.cs
trunk/mcs/class/corlib/System.Threading/HostExecutionContextManager.cs
Log:
2005-04-28 Sebastien Pouliot <[EMAIL PROTECTED]>
* AsyncFlowControl.cs: Updated wrt beta2.
* ExecutionContext.cs: Updated wrt beta2. Class is now internal in
NET_1_1 to allow the compressed stack propagation to other threads.
* CompressedStack.cs: Updated wrt beta2. Class is internal in NET_1_1
to allow the compressed stack propagation to other threads.
* ContextCallback.cs: Updated wrt beta2.
* HostExecutionContext.cs: Updated wrt beta2.
* HostExecutionContextManager.cs: Updated wrt beta2.
Modified: trunk/mcs/class/corlib/System.Threading/AsyncFlowControl.cs
===================================================================
--- trunk/mcs/class/corlib/System.Threading/AsyncFlowControl.cs 2005-04-28
12:09:31 UTC (rev 43714)
+++ trunk/mcs/class/corlib/System.Threading/AsyncFlowControl.cs 2005-04-28
12:13:22 UTC (rev 43715)
@@ -4,7 +4,7 @@
// Author:
// Sebastien Pouliot <[EMAIL PROTECTED]>
//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -28,32 +28,53 @@
#if NET_2_0
-using System;
using System.Globalization;
using System.Runtime.InteropServices;
+using System.Security;
namespace System.Threading {
- [ComVisibleAttribute (false)]
+ internal enum AsyncFlowControlType {
+ None,
+ Execution,
+ Security
+ }
+
public struct AsyncFlowControl : IDisposable {
- private bool _undo;
+ private Thread _t;
+ private AsyncFlowControlType _type;
- [MonoTODO]
+ internal AsyncFlowControl (Thread t, AsyncFlowControlType type)
+ {
+ _t = t;
+ _type = type;
+ }
+
public void Undo ()
{
- if (_undo) {
+ if (_t == null) {
throw new InvalidOperationException
(Locale.GetText (
"Can only be called once."));
}
- // TODO
- _undo = true;
+ switch (_type) {
+ case AsyncFlowControlType.Execution:
+ ExecutionContext.RestoreFlow ();
+ break;
+ case AsyncFlowControlType.Security:
+ SecurityContext.RestoreFlow ();
+ break;
+ }
+ _t = null;
}
void IDisposable.Dispose ()
{
- if (!_undo)
+ if (_t != null) {
Undo ();
+ _t = null;
+ _type = AsyncFlowControlType.None;
+ }
}
}
}
Modified: trunk/mcs/class/corlib/System.Threading/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Threading/ChangeLog 2005-04-28 12:09:31 UTC
(rev 43714)
+++ trunk/mcs/class/corlib/System.Threading/ChangeLog 2005-04-28 12:13:22 UTC
(rev 43715)
@@ -1,3 +1,14 @@
+2005-04-28 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * AsyncFlowControl.cs: Updated wrt beta2.
+ * ExecutionContext.cs: Updated wrt beta2. Class is now internal in
+ NET_1_1 to allow the compressed stack propagation to other threads.
+ * CompressedStack.cs: Updated wrt beta2. Class is internal in NET_1_1
+ to allow the compressed stack propagation to other threads.
+ * ContextCallback.cs: Updated wrt beta2.
+ * HostExecutionContext.cs: Updated wrt beta2.
+ * HostExecutionContextManager.cs: Updated wrt beta2.
+
2005-04-19 Zoltan Varga <[EMAIL PROTECTED]>
* Thread.cs: Add some unused fields.
Modified: trunk/mcs/class/corlib/System.Threading/CompressedStack.cs
===================================================================
--- trunk/mcs/class/corlib/System.Threading/CompressedStack.cs 2005-04-28
12:09:31 UTC (rev 43714)
+++ trunk/mcs/class/corlib/System.Threading/CompressedStack.cs 2005-04-28
12:13:22 UTC (rev 43715)
@@ -39,7 +39,6 @@
#if NET_2_0
[Serializable]
- [ComVisibleAttribute (false)]
public sealed class CompressedStack : ISerializable {
#else
public class CompressedStack {
@@ -58,33 +57,38 @@
_list = (ArrayList) cs._list.Clone ();
}
- ~CompressedStack ()
+#if NET_2_0
+ [ComVisibleAttribute (false)]
+ public
+#else
+ internal
+#endif
+ CompressedStack CreateCopy ()
{
+ return new CompressedStack (this);
}
#if NET_2_0
- [ComVisibleAttribute (false)]
- public CompressedStack CreateCopy ()
+ public
+#else
+ internal
+#endif
+ static CompressedStack Capture ()
{
- // FIXME: in 2.0 beta1 Object.ReferenceEquals (cs,
cs.CreateCopy ()) == true !!!
- return this;
-// return new CompressedStack (this);
+ 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");
}
- static public CompressedStack Capture ()
- {
- CompressedStack cs = new CompressedStack (0);
- cs._list = SecurityFrame.GetStack (1);
- return cs;
- }
-
[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode =
true)]
[StrongNameIdentityPermission (SecurityAction.LinkDemand,
PublicKey="00000000000000000400000000000000")]
static public CompressedStack GetCompressedStack ()
@@ -95,19 +99,27 @@
return new CompressedStack
(Thread.CurrentThread.GetCompressedStack ());
}
- static public CompressedStackSwitcher SetCompressedStack
(CompressedStack cs)
+ [SecurityPermission (SecurityAction.LinkDemand, Infrastructure
= true)]
+ static public void Run (CompressedStack compressedStack,
ContextCallback callback, object state)
{
+ if (compressedStack == null)
+ throw new ArgumentException ("compressedStack");
+
Thread t = Thread.CurrentThread;
- CompressedStack ctcs = t.GetCompressedStack ();
- if (ctcs != null) {
- string msg = Locale.GetText ("You must Undo
previous CompressedStack.");
- throw new SecurityException (msg);
+ CompressedStack original = null;
+ try {
+ original = t.GetCompressedStack ();
+ t.SetCompressedStack (compressedStack);
+ callback (state);
}
- CompressedStackSwitcher csw = new
CompressedStackSwitcher (ctcs, t);
- t.SetCompressedStack (cs);
- return csw;
+ finally {
+ if (original != null)
+ t.SetCompressedStack (original);
+ }
}
#endif
+ // internal stuff
+
internal bool Equals (CompressedStack cs)
{
if (IsEmpty ())
Modified: trunk/mcs/class/corlib/System.Threading/ContextCallback.cs
===================================================================
--- trunk/mcs/class/corlib/System.Threading/ContextCallback.cs 2005-04-28
12:09:31 UTC (rev 43714)
+++ trunk/mcs/class/corlib/System.Threading/ContextCallback.cs 2005-04-28
12:13:22 UTC (rev 43715)
@@ -4,7 +4,7 @@
// Author:
// Sebastien Pouliot <[EMAIL PROTECTED]>
//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -28,10 +28,11 @@
#if NET_2_0
-using System;
+using System.Runtime.InteropServices;
namespace System.Threading {
+ [ComVisible (true)]
public delegate void ContextCallback (object state);
}
Modified: trunk/mcs/class/corlib/System.Threading/ExecutionContext.cs
===================================================================
--- trunk/mcs/class/corlib/System.Threading/ExecutionContext.cs 2005-04-28
12:09:31 UTC (rev 43714)
+++ trunk/mcs/class/corlib/System.Threading/ExecutionContext.cs 2005-04-28
12:13:22 UTC (rev 43715)
@@ -1,13 +1,12 @@
//
// System.Threading.ExecutionContext.cs
//
-// Author:
-// Lluis Sanchez ([EMAIL PROTECTED])
+// Authors:
+// Lluis Sanchez ([EMAIL PROTECTED])
+// Sebastien Pouliot <[EMAIL PROTECTED]>
//
-// Copyright (C) Novell, Inc., 2004
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
-
-//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
@@ -28,20 +27,34 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
-
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
+using System.Security;
+using System.Security.Permissions;
-namespace System.Threading
-{
- [ComVisible (false)]
+namespace System.Threading {
+
[Serializable]
- public sealed class ExecutionContext : ISerializable
- {
+#if NET_2_0
+ public sealed class ExecutionContext : ISerializable {
+#else
+ internal sealed class ExecutionContext : ISerializable {
+#endif
+ private SecurityContext _sc;
+ private bool _suppressFlow;
+ private bool _capture;
+
internal ExecutionContext ()
{
}
+
+ internal ExecutionContext (ExecutionContext ec)
+ {
+ if (ec._sc != null)
+ _sc = new SecurityContext (ec._sc);
+ _suppressFlow = ec._suppressFlow;
+ _capture = true;
+ }
[MonoTODO]
internal ExecutionContext (SerializationInfo info,
StreamingContext context)
@@ -49,55 +62,90 @@
throw new NotImplementedException ();
}
- [MonoTODO]
- public static ExecutionContext Capture()
+ public static ExecutionContext Capture ()
{
- throw new NotImplementedException ();
+ ExecutionContext ec =
Thread.CurrentThread.ExecutionContext;
+ if (ec.FlowSuppressed)
+ return null;
+
+ ExecutionContext capture = new ExecutionContext (ec);
+ capture.SecurityContext = SecurityContext.Capture ();
+ return capture;
}
- [MonoTODO]
- public ExecutionContext CreateCopy()
+ public ExecutionContext CreateCopy ()
{
- throw new NotImplementedException ();
+ if (!_capture)
+ throw new InvalidOperationException ();
+
+ return new ExecutionContext (this);
}
[MonoTODO]
+ [ReflectionPermission (SecurityAction.Demand, MemberAccess =
true)]
public void GetObjectData (SerializationInfo info,
StreamingContext context)
{
+ if (info == null)
+ throw new ArgumentNullException ("info");
throw new NotImplementedException ();
}
- [MonoTODO]
- public static bool IsFlowSuppressed()
+ // internal stuff
+
+ internal SecurityContext SecurityContext {
+ get {
+ if (_sc == null)
+ _sc = new SecurityContext ();
+ return _sc;
+ }
+ set { _sc = value; }
+ }
+
+ internal bool FlowSuppressed {
+ get { return _suppressFlow; }
+ set { _suppressFlow = value; }
+ }
+
+#if NET_2_0
+ // Note: Previous to version 2.0 only the CompressedStack and
(sometimes!) the WindowsIdentity
+ // were propagated to new threads. This is why ExecutionContext
is internal in before NET_2_0.
+ // It also means that all newer context classes should be here
(i.e. inside the #if NET_2_0).
+
+ public static bool IsFlowSuppressed ()
{
- throw new NotImplementedException ();
+ return
Thread.CurrentThread.ExecutionContext.FlowSuppressed;
}
- [MonoTODO]
- public static void RestoreFlow()
+ public static void RestoreFlow ()
{
- throw new NotImplementedException ();
+ ExecutionContext ec =
Thread.CurrentThread.ExecutionContext;
+ if (!ec.FlowSuppressed)
+ throw new InvalidOperationException ();
+
+ ec.FlowSuppressed = false;
}
- [MonoTODO]
+ [MonoTODO ("only the SecurityContext is considered")]
+ [SecurityPermission (SecurityAction.LinkDemand, Infrastructure
= true)]
public static void Run (ExecutionContext executionContext,
ContextCallback callBack, object state)
{
- throw new NotImplementedException ();
+ if (executionContext == null) {
+ throw new InvalidOperationException
(Locale.GetText (
+ "Null ExecutionContext"));
+ }
+
+ // FIXME: supporting more than one context (the
SecurityContext)
+ // will requires a rewrite of this method
+
+ SecurityContext.Run (executionContext.SecurityContext,
callBack, state);
}
- [MonoTODO]
- public static ExecutionContextSwitcher SetExecutionContext
(ExecutionContext executionContext)
+ public static AsyncFlowControl SuppressFlow ()
{
- throw new NotImplementedException ();
+ Thread t = Thread.CurrentThread;
+ t.ExecutionContext.FlowSuppressed = true;
+ return new AsyncFlowControl (t,
AsyncFlowControlType.Execution);
}
-
- [MonoTODO]
- public static AsyncFlowControl SuppressFlow()
- {
- throw new NotImplementedException ();
- }
-
+#endif
}
}
-
-#endif
Modified: trunk/mcs/class/corlib/System.Threading/HostExecutionContext.cs
===================================================================
--- trunk/mcs/class/corlib/System.Threading/HostExecutionContext.cs
2005-04-28 12:09:31 UTC (rev 43714)
+++ trunk/mcs/class/corlib/System.Threading/HostExecutionContext.cs
2005-04-28 12:13:22 UTC (rev 43715)
@@ -4,7 +4,7 @@
// Author:
// Sebastien Pouliot <[EMAIL PROTECTED]>
//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -28,29 +28,32 @@
#if NET_2_0
-using System.Runtime.InteropServices;
-
namespace System.Threading {
- [ComVisible (false)]
+ [MonoTODO ("Useless until the runtime supports it")]
public class HostExecutionContext {
- protected internal object state;
+ private object _state;
public HostExecutionContext ()
{
- state = null;
+ _state = null;
}
public HostExecutionContext (object state)
{
- this.state = state;
+ _state = state;
}
public virtual HostExecutionContext CreateCopy ()
{
- return new HostExecutionContext (state);
+ return new HostExecutionContext (_state);
}
+
+ protected internal object State {
+ get { return _state; }
+ set { _state = value; }
+ }
}
}
Modified: trunk/mcs/class/corlib/System.Threading/HostExecutionContextManager.cs
===================================================================
--- trunk/mcs/class/corlib/System.Threading/HostExecutionContextManager.cs
2005-04-28 12:09:31 UTC (rev 43714)
+++ trunk/mcs/class/corlib/System.Threading/HostExecutionContextManager.cs
2005-04-28 12:13:22 UTC (rev 43715)
@@ -4,7 +4,7 @@
// Author:
// Sebastien Pouliot <[EMAIL PROTECTED]>
//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -28,12 +28,11 @@
#if NET_2_0
+using System.Security.Permissions;
using System.Runtime.ConstrainedExecution;
-using System.Runtime.InteropServices;
namespace System.Threading {
- [ComVisible (false)]
public class HostExecutionContextManager {
public HostExecutionContextManager ()
@@ -48,13 +47,14 @@
[MonoTODO]
[ReliabilityContract (Consistency.WillNotCorruptState,
CER.MayFail)]
- public virtual void Revert (HostExecutionContextSwitcher
hostContextSwitcher)
+ public virtual void Revert (object previousState)
{
throw new NotImplementedException ();
}
[MonoTODO]
- public virtual HostExecutionContextSwitcher
SetHostExecutionContext (HostExecutionContext hostExecutionContext)
+ [SecurityPermission (SecurityAction.LinkDemand, Infrastructure
= true)]
+ public virtual object SetHostExecutionContext
(HostExecutionContext hostExecutionContext)
{
throw new NotImplementedException ();
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches