Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@ -1,111 +0,0 @@
//
// System.Threading.AsyncFlowControl.cs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.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
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Runtime.InteropServices;
using System.Security;
namespace System.Threading {
internal enum AsyncFlowControlType {
None,
Execution,
Security
}
public struct AsyncFlowControl : IDisposable {
private Thread _t;
private AsyncFlowControlType _type;
internal AsyncFlowControl (Thread t, AsyncFlowControlType type)
{
_t = t;
_type = type;
}
public void Undo ()
{
if (_t == null) {
throw new InvalidOperationException (Locale.GetText (
"Can only be called once."));
}
switch (_type) {
case AsyncFlowControlType.Execution:
ExecutionContext.RestoreFlow ();
break;
case AsyncFlowControlType.Security:
SecurityContext.RestoreFlow ();
break;
}
_t = null;
}
public void Dispose ()
{
if (_t != null) {
Undo ();
_t = null;
_type = AsyncFlowControlType.None;
}
}
public override int GetHashCode ()
{
return(base.GetHashCode ());
}
public override bool Equals (object obj)
{
if (!(obj is AsyncFlowControl)) {
return(false);
}
return(obj.Equals (this));
}
public bool Equals (AsyncFlowControl obj)
{
if (this._t == obj._t &&
this._type == obj._type) {
return(true);
} else {
return(false);
}
}
public static bool operator == (AsyncFlowControl a, AsyncFlowControl b)
{
return a.Equals (b);
}
public static bool operator != (AsyncFlowControl a, AsyncFlowControl b)
{
return !a.Equals (b);
}
}
}

View File

@ -61,16 +61,20 @@ namespace System.Threading {
public static CompressedStack Capture ()
{
#if !FEATURE_COMPRESSEDSTACK
throw new NotSupportedException ();
#else
CompressedStack cs = new CompressedStack (0);
cs._list = SecurityFrame.GetStack (1);
cs._list = new ArrayList ();
// include any current CompressedStack inside the new Capture
CompressedStack currentCs = Thread.CurrentThread.GetCompressedStack ();
CompressedStack currentCs = Thread.CurrentThread.ExecutionContext.SecurityContext.CompressedStack;
if (currentCs != null) {
for (int i=0; i < currentCs._list.Count; i++)
cs._list.Add (currentCs._list [i]);
}
return cs;
#endif
}
// NOTE: This method doesn't show in the class library status page because
@ -79,13 +83,18 @@ namespace System.Threading {
[SecurityCritical]
static public CompressedStack GetCompressedStack ()
{
#if !FEATURE_COMPRESSEDSTACK
throw new NotSupportedException ();
#else
// Note: CompressedStack.GetCompressedStack doesn't return null
// like Thread.CurrentThread.GetCompressedStack if no compressed
// stack is present.
CompressedStack cs = Thread.CurrentThread.GetCompressedStack ();
if (cs == null) {
CompressedStack cs = Thread.CurrentThread.ExecutionContext.SecurityContext.CompressedStack;
if (cs == null || cs.IsEmpty ()) {
cs = CompressedStack.Capture ();
} else {
cs = cs.CreateCopy ();
// 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 ();
@ -93,6 +102,7 @@ namespace System.Threading {
cs._list.Add (newstack._list [i]);
}
return cs;
#endif
}
[MonoTODO ("incomplete")]
@ -106,20 +116,24 @@ namespace System.Threading {
[SecurityCritical]
static public void Run (CompressedStack compressedStack, ContextCallback callback, object state)
{
#if !FEATURE_COMPRESSEDSTACK
throw new NotSupportedException ();
#else
if (compressedStack == null)
throw new ArgumentException ("compressedStack");
Thread t = Thread.CurrentThread;
CompressedStack original = null;
try {
original = t.GetCompressedStack ();
t.SetCompressedStack (compressedStack);
original = t.ExecutionContext.SecurityContext.CompressedStack;
t.ExecutionContext.SecurityContext.CompressedStack = compressedStack;
callback (state);
}
finally {
if (original != null)
t.SetCompressedStack (original);
t.ExecutionContext.SecurityContext.CompressedStack = original;
}
#endif
}
// internal stuff
@ -132,12 +146,6 @@ namespace System.Threading {
if (_list.Count != cs._list.Count)
return false;
for (int i=0; i < _list.Count; i++) {
SecurityFrame sf1 = (SecurityFrame) _list [i];
SecurityFrame sf2 = (SecurityFrame) cs._list [i];
if (!sf1.Equals (sf2))
return false;
}
return true;
}

View File

@ -1,36 +0,0 @@
//
// System.Threading.ContextCallback delegate
//
// Author:
// Sebastien Pouliot <sebastien@ximian.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
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Threading {
[ComVisible (true)]
public delegate void ContextCallback (object state);
}

View File

@ -1,294 +0,0 @@
//
// System.Threading.ExecutionContext.cs
//
// Authors:
// Lluis Sanchez (lluis@novell.com)
// Sebastien Pouliot <sebastien@ximian.com>
// Marek Safar (marek.safar@gmail.com)
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.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
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Runtime.Remoting.Messaging;
using System.Collections.Generic;
namespace System.Threading {
[Serializable]
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 ExecutionContext ()
{
}
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 ();
}
[MonoTODO]
internal ExecutionContext (SerializationInfo info, StreamingContext context)
{
throw new NotImplementedException ();
}
public static ExecutionContext Capture ()
{
return Capture (true, false);
}
internal static ExecutionContext Capture (bool captureSyncContext, bool nullOnEmpty)
{
var thread = Thread.CurrentThread;
if (nullOnEmpty && !thread.HasExecutionContext)
return null;
var ec = thread.ExecutionContext;
if (ec.FlowSuppressed)
return null;
if (nullOnEmpty
#if !MOBILE
&& ec._sc == null
#endif
&& (ec._lcc == null || !ec._lcc.HasInfo))
return null;
ExecutionContext capture = new ExecutionContext (ec);
#if !MOBILE
if (SecurityManager.SecurityEnabled)
capture.SecurityContext = SecurityContext.Capture ();
#endif
return capture;
}
public ExecutionContext CreateCopy ()
{
if (!_capture)
throw new InvalidOperationException ();
return new ExecutionContext (this);
}
public void Dispose ()
{
#if !MOBILE
if (_sc != null)
_sc.Dispose ();
#endif
}
[MonoTODO]
[ReflectionPermission (SecurityAction.Demand, MemberAccess = true)]
public void GetObjectData (SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException ("info");
throw new NotImplementedException ();
}
// internal stuff
internal LogicalCallContext LogicalCallContext {
get {
if (_lcc == null)
_lcc = new LogicalCallContext ();
return _lcc;
}
set {
_lcc = value;
}
}
internal Dictionary<string, object> DataStore {
get {
if (local_data == null)
local_data = new Dictionary<string, object> ();
return local_data;
}
set {
local_data = value;
}
}
#if !MOBILE
internal SecurityContext SecurityContext {
get {
if (_sc == null)
_sc = new SecurityContext ();
return _sc;
}
set { _sc = value; }
}
#endif
internal bool FlowSuppressed {
get { return _suppressFlow; }
set { _suppressFlow = value; }
}
internal bool CopyOnWrite { get; set; }
public static bool IsFlowSuppressed ()
{
return Current.FlowSuppressed;
}
public static void RestoreFlow ()
{
ExecutionContext ec = Current;
if (!ec.FlowSuppressed)
throw new InvalidOperationException ();
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)
{
if (executionContext == null) {
throw new InvalidOperationException (Locale.GetText (
"Null ExecutionContext"));
}
var prev = Current;
try {
Thread.CurrentThread.ExecutionContext = executionContext;
callback (state);
} finally {
Thread.CurrentThread.ExecutionContext = prev;
}
}
public static AsyncFlowControl SuppressFlow ()
{
Thread t = Thread.CurrentThread;
t.ExecutionContext.FlowSuppressed = true;
return new AsyncFlowControl (t, AsyncFlowControlType.Execution);
}
internal static LogicalCallContext CreateLogicalCallContext (bool createEmpty)
{
var lcc = Current._lcc;
if (lcc == null) {
if (createEmpty)
lcc = new LogicalCallContext ();
return lcc;
}
return (LogicalCallContext) lcc.Clone ();
}
internal void FreeNamedDataSlot (string name)
{
if (_lcc != null)
_lcc.FreeNamedDataSlot (name);
if (local_data != null)
local_data.Remove (name);
}
internal static ExecutionContext Current {
get {
return Thread.CurrentThread.ExecutionContext;
}
}
internal static ExecutionContext GetCurrentWritable ()
{
var current = Thread.CurrentThread.ExecutionContext;
if (current.CopyOnWrite) {
current.CopyOnWrite = false;
current.CloneData (current);
}
return current;
}
}
}

View File

@ -1,42 +0,0 @@
//
// System.Threading.IOCompletionCallback.cs
//
// Author:
// Dick Porter (dick@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 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
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Threading
{
// 'unsafe' wasn't in the spec, but the compiler insists because of
// the pointer.
[ComVisible (true)]
[CLSCompliant(false)]
public unsafe delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP);
}

View File

@ -1,64 +0,0 @@
/*
* System.Threading.LockRecursionException
*
* Author(s)
* Marek Safar <marek.safar@gmail.com>
*
* Copyright 2011 Xamarin Inc (http://www.xamarin.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
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
namespace System.Threading
{
[Serializable]
#if !MOBILE
[TypeForwardedFrom (Consts.AssemblySystemCore_3_5)]
#endif
public class LockRecursionException : Exception
{
public LockRecursionException ()
: base ()
{
}
public LockRecursionException (string message)
: base (message)
{
}
public LockRecursionException (string message, Exception innerException)
: base (message, innerException)
{
}
protected LockRecursionException (SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
}
}

View File

@ -1,86 +0,0 @@
//
// NamedDataSlot.cs:
//
// Authors:
// Dick Porter (dick@ximian.com)
// Marek Safar (marek.safar@gmail.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2006 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
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections.Generic;
namespace System.Threading
{
sealed class NamedDataSlot
{
// Stores a hash keyed by strings of LocalDataStoreSlot objects
Dictionary<string, LocalDataStoreSlot> datastorehash;
public LocalDataStoreSlot Allocate (string name)
{
lock (this) {
if (datastorehash == null)
datastorehash = new Dictionary<string, LocalDataStoreSlot> ();
if (datastorehash.ContainsKey (name)) {
// This exception isnt documented (of
// course) but .net throws it
throw new ArgumentException ("Named data slot already added");
}
var slot = new LocalDataStoreSlot (true);
datastorehash.Add (name, slot);
return slot;
}
}
public LocalDataStoreSlot Get (string name)
{
lock (this) {
if (datastorehash == null)
datastorehash = new Dictionary<string, LocalDataStoreSlot> ();
LocalDataStoreSlot slot;
if (!datastorehash.TryGetValue (name, out slot)) {
slot = new LocalDataStoreSlot (true);
datastorehash.Add (name, slot);
}
return slot;
}
}
public void Free (string name)
{
lock (this) {
if (datastorehash == null)
datastorehash = new Dictionary<string, LocalDataStoreSlot> ();
if (datastorehash.ContainsKey (name)) {
datastorehash.Remove (name);
}
}
}
}
}

View File

@ -1,133 +0,0 @@
//
// System.Threading.SynchronizationContext.cs
//
// Author:
// Lluis Sanchez (lluis@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
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
namespace System.Threading
{
public class SynchronizationContext
{
bool notification_required;
[ThreadStatic]
static SynchronizationContext currentContext;
public SynchronizationContext ()
{
}
internal SynchronizationContext (SynchronizationContext context)
{
currentContext = context;
}
public static SynchronizationContext Current {
get {
#if MONODROID
if (currentContext == null)
currentContext = AndroidPlatform.GetDefaultSyncContext ();
#endif
return currentContext;
}
}
// extracted from ../../../../external/referencesource/mscorlib/system/threading/synchronizationcontext.cs
// Get the last SynchronizationContext that was set explicitly (not flowed via ExecutionContext.Capture/Run)
internal static SynchronizationContext CurrentNoFlow
{
get
{
// FIXME get context not flowed
return Current;
}
}
public virtual SynchronizationContext CreateCopy ()
{
return new SynchronizationContext (this);
}
public bool IsWaitNotificationRequired ()
{
return notification_required;
}
public virtual void OperationCompleted ()
{
}
public virtual void OperationStarted ()
{
}
public virtual void Post (SendOrPostCallback d, object state)
{
ThreadPool.QueueUserWorkItem (new WaitCallback (d), state);
}
public virtual void Send (SendOrPostCallback d, object state)
{
d (state);
}
public static void SetSynchronizationContext (SynchronizationContext syncContext)
{
currentContext = syncContext;
}
#if NET_2_1
[Obsolete]
public static void SetThreadStaticContext (SynchronizationContext syncContext)
{
currentContext = syncContext;
}
#endif
protected void SetWaitNotificationRequired ()
{
notification_required = true;
}
[CLSCompliant (false)]
[PrePrepareMethod ()]
public virtual int Wait (IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
{
return WaitHelper (waitHandles, waitAll, millisecondsTimeout);
}
[MonoTODO]
[CLSCompliant (false)]
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
[PrePrepareMethod ()]
protected static int WaitHelper (IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
{
throw new NotImplementedException ();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,60 +0,0 @@
//
// System.Threading.ThreadAbortException.cs
//
// Author:
// Dick Porter (dick@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 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
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
namespace System.Threading
{
[Serializable]
[ComVisible (true)]
public sealed class ThreadAbortException : SystemException
{
private ThreadAbortException () : base ("Thread was being aborted")
{
HResult = unchecked ((int) 0x80131530);
}
private ThreadAbortException (SerializationInfo info, StreamingContext sc) : base (info, sc)
{
}
#if !NET_2_1
public object ExceptionState {
get {
return Thread.CurrentThread.GetAbortExceptionState ();
}
}
#endif
}
}

View File

@ -1,58 +0,0 @@
//
// System.Threading.ThreadInterruptedException.cs
//
// Author:
// Dick Porter (dick@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 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
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
namespace System.Threading
{
[Serializable]
[ComVisible (true)]
public class ThreadInterruptedException : SystemException
{
public ThreadInterruptedException()
: base ("Thread interrupted") {
}
public ThreadInterruptedException(string message)
: base (message) {
}
protected ThreadInterruptedException(SerializationInfo info, StreamingContext context)
: base (info, context) {
}
public ThreadInterruptedException(string message, Exception innerException)
: base (message, innerException) {
}
}
}

View File

@ -1,165 +0,0 @@
//
// ThreadLocal.cs
//
// Author:
// Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
// Rewritten by Paolo Molaro (lupus@ximian.com)
//
// Copyright (c) 2009 Jérémie "Garuma" Laval
//
// 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 without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.Security.Permissions;
namespace System.Threading
{
[System.Diagnostics.DebuggerDisplay ("IsValueCreated={IsValueCreated}, Value={ValueForDebugDisplay}")]
public class ThreadLocal<T> : IDisposable
{
struct TlsDatum {
internal sbyte state; /* 0 uninitialized, < 0 initializing, > 0 inited */
internal Exception cachedException; /* this is per-thread */
internal T data;
}
Func<T> valueFactory;
/* The tlsdata field is handled magically by the JIT
* It must be a struct and it is always accessed by ldflda: the JIT, instead of
* computing the address inside the instance, will return the address of the variable
* for the current thread (based on tls_offset). This magic wouldn't be needed if C#
* let us declare an icall with a TlsDatum& return type...
* For this same reason, we must check tls_offset for != 0 to make sure it's valid before accessing tlsdata
* The address of the tls var is cached per method at the first IL ldflda instruction, so care must be taken
* not to cause it to be conditionally executed.
*/
uint tls_offset;
TlsDatum tlsdata;
public ThreadLocal ()
{
tls_offset = Thread.AllocTlsData (typeof (TlsDatum));
}
public ThreadLocal (Func<T> valueFactory) : this ()
{
if (valueFactory == null)
throw new ArgumentNullException ("valueFactory");
this.valueFactory = valueFactory;
}
public ThreadLocal (bool trackAllValues) : this () {
if (trackAllValues)
throw new NotImplementedException ();
}
public ThreadLocal (Func<T> valueFactory, bool trackAllValues) : this (valueFactory) {
if (trackAllValues)
throw new NotImplementedException ();
}
public void Dispose ()
{
Dispose (true);
}
protected virtual void Dispose (bool disposing)
{
if (tls_offset != 0) {
uint o = tls_offset;
tls_offset = 0;
if (disposing)
valueFactory = null;
Thread.DestroyTlsData (o);
GC.SuppressFinalize (this);
}
}
~ThreadLocal ()
{
Dispose (false);
}
public bool IsValueCreated {
get {
if (tls_offset == 0)
throw new ObjectDisposedException ("ThreadLocal object");
/* ALERT! magic tlsdata JIT access redirects to TLS value instead of instance field */
return tlsdata.state > 0;
}
}
T GetSlowPath () {
/* ALERT! magic tlsdata JIT access redirects to TLS value instead of instance field */
if (tlsdata.cachedException != null)
throw tlsdata.cachedException;
if (tlsdata.state < 0)
throw new InvalidOperationException ("The initialization function attempted to reference Value recursively");
tlsdata.state = -1;
if (valueFactory != null) {
try {
tlsdata.data = valueFactory ();
} catch (Exception ex) {
tlsdata.cachedException = ex;
throw ex;
}
} else {
tlsdata.data = default (T);
}
tlsdata.state = 1;
return tlsdata.data;
}
[System.Diagnostics.DebuggerBrowsableAttribute (System.Diagnostics.DebuggerBrowsableState.Never)]
public T Value {
get {
if (tls_offset == 0)
throw new ObjectDisposedException ("ThreadLocal object");
/* ALERT! magic tlsdata JIT access redirects to TLS value instead of instance field */
if (tlsdata.state > 0)
return tlsdata.data;
return GetSlowPath ();
}
set {
if (tls_offset == 0)
throw new ObjectDisposedException ("ThreadLocal object");
/* ALERT! magic tlsdata JIT access redirects to TLS value instead of instance field */
tlsdata.state = 1;
tlsdata.data = value;
}
}
public IList<T> Values {
get {
if (tls_offset == 0)
throw new ObjectDisposedException ("ThreadLocal object");
throw new NotImplementedException ();
}
}
public override string ToString ()
{
return Value.ToString ();
}
}
}

View File

@ -1,276 +0,0 @@
//
// System.Threading.ThreadPool.cs
//
// Author:
// Patrik Torstensson
// Dick Porter (dick@ximian.com)
// Maurer Dietmar (dietmar@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.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
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting.Messaging;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
namespace System.Threading {
// Extracted from ../../../../external/referencesource/mscorlib/system/threading/threadpool.cs
//
// Interface to something that can be queued to the TP. This is implemented by
// QueueUserWorkItemCallback, Task, and potentially other internal types.
// For example, SemaphoreSlim represents callbacks using its own type that
// implements IThreadPoolWorkItem.
//
// If we decide to expose some of the workstealing
// stuff, this is NOT the thing we want to expose to the public.
//
internal interface IThreadPoolWorkItem
{
[SecurityCritical]
void ExecuteWorkItem();
[SecurityCritical]
void MarkAborted(ThreadAbortException tae);
}
public static class ThreadPool {
[Obsolete("This method is obsolete, use BindHandle(SafeHandle) instead")]
public static bool BindHandle (IntPtr osHandle)
{
return true;
}
public static bool BindHandle (SafeHandle osHandle)
{
if (osHandle == null)
throw new ArgumentNullException ("osHandle");
return true;
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void GetAvailableThreads (out int workerThreads, out int completionPortThreads);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void GetMaxThreads (out int workerThreads, out int completionPortThreads);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void GetMinThreads (out int workerThreads, out int completionPortThreads);
[MonoTODO("The min number of completion port threads is not evaluated.")]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
public static extern bool SetMinThreads (int workerThreads, int completionPortThreads);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
public static extern bool SetMaxThreads (int workerThreads, int completionPortThreads);
public static bool QueueUserWorkItem (WaitCallback callBack)
{
return QueueUserWorkItem (callBack, null);
}
public static bool QueueUserWorkItem (WaitCallback callBack, object state)
{
if (callBack == null)
throw new ArgumentNullException ("callBack");
if (callBack.IsTransparentProxy ()) {
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
} else {
AsyncResult ares = new AsyncResult (callBack, state, true);
pool_queue (ares);
}
return true;
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern void pool_queue (AsyncResult ares);
// TODO: It should be interface interface only to avoid extra allocation
internal static void QueueWorkItem (WaitCallback callBack, object state)
{
pool_queue (new AsyncResult (callBack, state, false));
}
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
int millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
return RegisterWaitForSingleObject (waitObject, callBack, state,
(long) millisecondsTimeOutInterval, executeOnlyOnce);
}
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
long millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
if (waitObject == null)
throw new ArgumentNullException ("waitObject");
if (callBack == null)
throw new ArgumentNullException ("callBack");
if (millisecondsTimeOutInterval < -1)
throw new ArgumentOutOfRangeException ("timeout", "timeout < -1");
if (millisecondsTimeOutInterval > Int32.MaxValue)
throw new NotSupportedException ("Timeout is too big. Maximum is Int32.MaxValue");
TimeSpan timeout = new TimeSpan (0, 0, 0, 0, (int) millisecondsTimeOutInterval);
RegisteredWaitHandle waiter = new RegisteredWaitHandle (waitObject, callBack, state,
timeout, executeOnlyOnce);
QueueUserWorkItem (new WaitCallback (waiter.Wait), null);
return waiter;
}
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
TimeSpan timeout,
bool executeOnlyOnce)
{
return RegisterWaitForSingleObject (waitObject, callBack, state,
(long) timeout.TotalMilliseconds, executeOnlyOnce);
}
[CLSCompliant(false)]
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
uint millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
return RegisterWaitForSingleObject (waitObject, callBack, state,
(long) millisecondsTimeOutInterval, executeOnlyOnce);
}
[CLSCompliant (false)]
unsafe public static bool UnsafeQueueNativeOverlapped (NativeOverlapped *overlapped)
{
throw new NotImplementedException ();
}
#if !NET_2_1 || MOBILE
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
public static bool UnsafeQueueUserWorkItem (WaitCallback callBack, object state)
{
if (callBack == null)
throw new ArgumentNullException ("callBack");
// no stack propagation here (that's why it's unsafe and requires extra security permissions)
if (!callBack.IsTransparentProxy ()) {
AsyncResult ares = new AsyncResult (callBack, state, false);
pool_queue (ares);
return true;
}
try {
if (!ExecutionContext.IsFlowSuppressed ())
ExecutionContext.SuppressFlow (); // on current thread only
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
} finally {
if (ExecutionContext.IsFlowSuppressed ())
ExecutionContext.RestoreFlow ();
}
return true;
}
[MonoTODO("Not implemented")]
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
throw new NotImplementedException ();
}
[MonoTODO("Not implemented")]
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
throw new NotImplementedException ();
}
[MonoTODO("Not implemented")]
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack, object state, TimeSpan timeout,
bool executeOnlyOnce)
{
throw new NotImplementedException ();
}
[MonoTODO("Not implemented")]
[CLSCompliant (false)]
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
throw new NotImplementedException ();
}
#endif
#region ReferenceSources
// Extracted from ../../../../external/referencesource/mscorlib/system/threading/threadpool.cs
internal static void UnsafeQueueCustomWorkItem(IThreadPoolWorkItem workItem, bool forceGlobal)
{
QueueWorkItem ((obj) => ((IThreadPoolWorkItem)obj).ExecuteWorkItem (), workItem);
}
internal static IEnumerable<IThreadPoolWorkItem> GetQueuedWorkItems()
{
yield break;
}
internal static bool TryPopCustomWorkItem(IThreadPoolWorkItem workItem)
{
return false;
}
internal static void NotifyWorkItemProgress()
{
}
#endregion
}
}

View File

@ -347,7 +347,7 @@ namespace System.Threading
list.RemoveAt (i);
count--;
i--;
ThreadPool.QueueWorkItem (TimerCB, timer);
ThreadPool.UnsafeQueueUserWorkItem (TimerCB, timer);
long period = timer.period_ms;
long due_time = timer.due_time_ms;
bool no_more = (period == -1 || ((period == 0 || period == Timeout.Infinite) && due_time != Timeout.Infinite));

View File

@ -1,39 +0,0 @@
//
// System.Threading.WaitCallback.cs
//
// Author:
// Dick Porter (dick@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 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
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Threading
{
[ComVisible (true)]
public delegate void WaitCallback(object state);
}

View File

@ -1,39 +0,0 @@
//
// System.Threading.WaitOrTimerCallback.cs
//
// Author:
// Dick Porter (dick@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 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
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Threading
{
[ComVisible (true)]
public delegate void WaitOrTimerCallback(object state, bool timedOut);
}