Imported Upstream version 4.2.0.179

Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent 183bba2c9a
commit 6992685b86
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -586,7 +586,7 @@ namespace System.Threading
/// </summary>
private static int GetNewTableSize(int minSize)
{
if ((uint)minSize > Array.MaxArrayLength)
if ((uint)minSize > Array_ReferenceSources.MaxArrayLength)
{
// Intentionally return a value that will result in an OutOfMemoryException
return int.MaxValue;
@@ -621,9 +621,9 @@ namespace System.Threading
newSize++;
// Don't set newSize to more than Array.MaxArrayLength
if ((uint)newSize > Array.MaxArrayLength)
if ((uint)newSize > Array_ReferenceSources.MaxArrayLength)
{
newSize = Array.MaxArrayLength;
newSize = Array_ReferenceSources.MaxArrayLength;
}
return newSize;

View File

@@ -99,7 +99,7 @@ namespace System.Threading
#endif
currentThread.SetExecutionContext(outerEC, outerECBelongsToScope);
#if DEBUG
#if !MONO && DEBUG
try
{
currentThread.ForbidExecutionContextMutation = true;
@@ -121,7 +121,7 @@ namespace System.Threading
#endif
thread = null; // this will prevent the switcher object being used again
#if DEBUG
#if !MONO && DEBUG
}
finally
{

View File

@@ -26,7 +26,9 @@ namespace System.Threading
[Serializable]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
#if !MOBILE
[TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public class LockRecursionException : System.Exception
{
public LockRecursionException() { }

View File

@@ -16,7 +16,9 @@
namespace System.Threading
{
#if !MONO
using Microsoft.Win32.SafeHandles;
#endif
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
@@ -164,9 +166,16 @@ namespace System.Threading
[CLSCompliant(false)]
[PrePrepareMethod]
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
#if MONO
protected static int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
{
throw new NotImplementedException ();
}
#else
[MethodImplAttribute(MethodImplOptions.InternalCall)]
protected static extern int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout);
#endif
#endif
// set SynchronizationContext on the current thread
@@ -181,7 +190,7 @@ namespace System.Threading
ec.SynchronizationContextNoFlow = syncContext;
}
#if FEATURE_CORECLR
#if FEATURE_CORECLR || MOBILE_LEGACY
//
// This is a framework-internal method for Jolt's use. The problem is that SynchronizationContexts set inside of a reverse p/invoke
// into an AppDomain are not persisted in that AppDomain; the next time the same thread calls into the same AppDomain,
@@ -210,7 +219,7 @@ namespace System.Threading
#endif
[System.Security.SecurityCritical]
#if FEATURE_LEGACYNETCF
#if FEATURE_LEGACYNETCF || MOBILE_LEGACY
public static void SetThreadStaticContext(SynchronizationContext syncContext)
#else
internal static void SetThreadStaticContext(SynchronizationContext syncContext)
@@ -271,6 +280,11 @@ namespace System.Threading
context = GetWinRTContext();
#endif
#if MONODROID
if (context == null)
context = AndroidPlatform.GetDefaultSyncContext ();
#endif
return context;
}

View File

@@ -110,7 +110,7 @@ namespace System.Threading {
}
}
}
#if !MONO
internal struct ThreadHandle
{
private IntPtr m_ptr;
@@ -120,13 +120,17 @@ namespace System.Threading {
m_ptr = pThread;
}
}
#endif
// deliberately not [serializable]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_Thread))]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Thread : CriticalFinalizerObject, _Thread
public sealed partial class Thread : CriticalFinalizerObject
#if !MOBILE
, _Thread
#endif
{
#if !MONO
/*=========================================================================
** Data accessed from managed code that needs to be defined in
** ThreadBaseObject to maintain alignment between the two classes.
@@ -168,7 +172,7 @@ namespace System.Threading {
#if DEBUG
private bool m_ForbidExecutionContextMutation;
#endif
#endif
/*=========================================================================
** This manager is responsible for storing the global data that is
** shared amongst all the thread local stores.
@@ -222,6 +226,7 @@ namespace System.Threading {
Contract.EndContractBlock();
SetStartHelper((Delegate)start, maxStackSize);
}
[System.Security.SecuritySafeCritical] // auto-generated
public Thread(ParameterizedThreadStart start) {
if (start == null) {
@@ -241,7 +246,7 @@ namespace System.Threading {
Contract.EndContractBlock();
SetStartHelper((Delegate)start, maxStackSize);
}
#if !MONO
[ComVisible(false)]
public override int GetHashCode()
{
@@ -270,7 +275,7 @@ namespace System.Threading {
return new ThreadHandle(thread);
}
#endif
/*=========================================================================
** Spawns off a new thread which will begin executing at the ThreadStart
@@ -326,7 +331,11 @@ namespace System.Threading {
ExecutionContext.CaptureOptions.IgnoreSyncCtx);
t.SetExecutionContextHelper(ec);
}
#if FEATURE_ROLE_BASED_SECURITY
IPrincipal principal = (IPrincipal)CallContext.Principal;
#else
IPrincipal principal = null;
#endif
StartInternal(principal, ref stackMark);
}
@@ -343,7 +352,7 @@ namespace System.Threading {
set { m_ExecutionContextBelongsToOuterScope = !value; }
}
#if DEBUG
#if !MONO && DEBUG
internal bool ForbidExecutionContextMutation
{
set { m_ForbidExecutionContextMutation = value; }
@@ -372,7 +381,7 @@ namespace System.Threading {
internal ExecutionContext GetMutableExecutionContext()
{
Contract.Assert(Thread.CurrentThread == this);
#if DEBUG
#if !MONO && DEBUG
Contract.Assert(!m_ForbidExecutionContextMutation);
#endif
if (m_ExecutionContext == null)
@@ -404,12 +413,13 @@ namespace System.Threading {
m_ExecutionContext = value.DangerousGetRawExecutionContext();
ExecutionContextBelongsToCurrentScope = belongsToCurrentScope;
}
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern void StartInternal(IPrincipal principal, ref StackCrawlMark stackMark);
#if FEATURE_COMPRESSEDSTACK
#endif
#if FEATURE_COMPRESSEDSTACK || MONO
/// <internalonly/>
[System.Security.SecurityCritical] // auto-generated_required
[DynamicSecurityMethodAttribute()]
@@ -418,7 +428,7 @@ namespace System.Threading {
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ThreadAPIsNotSupported"));
}
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
@@ -428,7 +438,7 @@ namespace System.Threading {
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal extern void RestoreAppDomainStack( IntPtr appDomainStack);
#endif
/// <internalonly/>
[System.Security.SecurityCritical] // auto-generated_required
@@ -438,7 +448,7 @@ namespace System.Threading {
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ThreadAPIsNotSupported"));
}
#endif // #if FEATURE_COMPRESSEDSTACK
#if !MONO
// Helper method to get a logical thread ID for StringBuilder (for
// correctness) and for FileStream's async code path (for perf, to
@@ -524,8 +534,8 @@ namespace System.Threading {
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern void AbortInternal();
#if !FEATURE_CORECLR
#endif
#if !FEATURE_CORECLR || MONO
/*=========================================================================
** Resets a thread abort.
** Should be called by trusted code only
@@ -621,7 +631,7 @@ namespace System.Threading {
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern void SetPriorityNative(int priority);
#if !MONO
/*=========================================================================
** Returns true if the thread has been started and is not dead.
=========================================================================*/
@@ -639,7 +649,7 @@ namespace System.Threading {
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
#endif
/*=========================================================================
** Waits for the thread to die or for timeout milliseconds to elapse.
** Returns true if the thread died, or false if the wait timed out. If
@@ -665,6 +675,10 @@ namespace System.Threading {
[HostProtection(Synchronization=true, ExternalThreading=true)]
public bool Join(int millisecondsTimeout)
{
#if MONO
if (millisecondsTimeout < Timeout.Infinite)
throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
#endif
return JoinInternal(millisecondsTimeout);
}
@@ -694,10 +708,16 @@ namespace System.Threading {
[System.Security.SecuritySafeCritical] // auto-generated
public static void Sleep(int millisecondsTimeout)
{
#if MONO
if (millisecondsTimeout < Timeout.Infinite)
throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
#endif
SleepInternal(millisecondsTimeout);
#if !MONO
// Ensure we don't return to app code when the pause is underway
if(AppDomainPauseManager.IsPaused)
AppDomainPauseManager.ResumeEvent.WaitOneWithoutFAS();
#endif
}
public static void Sleep(TimeSpan timeout)
@@ -708,7 +728,7 @@ namespace System.Threading {
Sleep((int)tm);
}
#if !MONO
/* wait for a length of time proportial to 'iterations'. Each iteration is should
only take a few machine instructions. Calling this API is preferable to coding
a explict busy loop because the hardware can be informed that it is busy waiting. */
@@ -727,7 +747,7 @@ namespace System.Threading {
{
SpinWaitInternal(iterations);
}
#endif
[System.Security.SecurityCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall),
HostProtection(Synchronization = true, ExternalThreading = true),
@@ -742,7 +762,8 @@ namespace System.Threading {
{
return YieldInternal();
}
#if !MONO
public static Thread CurrentThread {
[System.Security.SecuritySafeCritical] // auto-generated
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
@@ -758,10 +779,13 @@ namespace System.Threading {
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall), ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
private static extern Thread GetCurrentThreadNative();
#endif
[System.Security.SecurityCritical] // auto-generated
private void SetStartHelper(Delegate start, int maxStackSize)
{
#if MONO
maxStackSize = GetProcessDefaultStackSize(maxStackSize);
#else
#if FEATURE_CORECLR
// We only support default stacks in CoreCLR
Contract.Assert(maxStackSize == 0);
@@ -769,6 +793,7 @@ namespace System.Threading {
// Only fully-trusted code is allowed to create "large" stacks. Partial-trust falls back to
// the default stack size.
ulong defaultStackSize = GetProcessDefaultStackSize();
if ((ulong)(uint)maxStackSize > defaultStackSize)
{
try
@@ -780,6 +805,7 @@ namespace System.Threading {
maxStackSize = (int)Math.Min(defaultStackSize, (ulong)(uint)int.MaxValue);
}
}
#endif
#endif
ThreadHelper threadStartCallBack = new ThreadHelper(start);
@@ -792,7 +818,7 @@ namespace System.Threading {
SetStart(new ParameterizedThreadStart(threadStartCallBack.ThreadStart), maxStackSize);
}
}
#if !MONO
[SecurityCritical]
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
@@ -948,7 +974,7 @@ namespace System.Threading {
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern void StartupSetApartmentStateInternal();
#endif // FEATURE_COMINTEROP_APARTMENT_SUPPORT
#endif
/*=========================================================================
** Allocates an un-named data slot. The slot is allocated on ALL the
** threads.
@@ -1027,7 +1053,7 @@ namespace System.Threading {
dls.Store.SetData(slot, data);
}
#if !MONO
// #threadCultureInfo
//
@@ -1693,7 +1719,7 @@ namespace System.Threading {
MemoryBarrier(); // Call MemoryBarrier to ensure the proper semantic in a portable way.
address = value;
}
#endif
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -1711,7 +1737,7 @@ namespace System.Threading {
return s_LocalDataStoreMgr;
}
}
#if !MOBILE
void _Thread.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
@@ -1731,7 +1757,8 @@ namespace System.Threading {
{
throw new NotImplementedException();
}
#endif
#if !MONO
// Helper function to set the AbortReason for a thread abort.
// Checks that they're not alredy set, and then atomically updates
// the reason info (object + ADID).
@@ -1754,7 +1781,7 @@ namespace System.Threading {
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern void ClearAbortReason();
#endif
} // End of class Thread

View File

@@ -39,11 +39,12 @@ namespace System.Threading
: base(info, context)
{
}
#if !MOBILE
public Object ExceptionState
{
[System.Security.SecuritySafeCritical] // auto-generated
get {return Thread.CurrentThread.AbortReason;}
}
#endif
}
}

View File

@@ -33,7 +33,20 @@
namespace System.Threading
{
using System.Security;
using System.Runtime.Remoting;
using System.Security.Permissions;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
#if !MONO
using Microsoft.Win32;
#endif
//
// Interface to something that can be queued to the TP. This is implemented by
@@ -62,25 +75,6 @@ namespace System.Threading
[CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
unsafe public delegate void IOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped* pOVERLAP);
}
namespace System.Threading.Microsoft
{
using System.Security;
using System.Runtime.Remoting;
using System.Security.Permissions;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
#if !MONO
using Microsoft.Win32;
#endif
internal static class ThreadPoolGlobals
{
@@ -1373,8 +1367,6 @@ namespace System.Threading.Microsoft
[HostProtection(Synchronization=true, ExternalThreading=true)]
public static class ThreadPool
{
internal static readonly bool UseMicrosoftThreadPool = Environment.GetEnvironmentVariable ("MONO_THREADPOOL") == "microsoft";
#if FEATURE_CORECLR
[System.Security.SecurityCritical] // auto-generated
#else
@@ -1897,6 +1889,7 @@ namespace System.Threading.Microsoft
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void InitializeVMTp(ref bool enableWorkerTracking);
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -1909,6 +1902,7 @@ namespace System.Threading.Microsoft
ref StackCrawlMark stackMark,
bool compressStack
);
#endif
#if !FEATURE_CORECLR
[System.Security.SecuritySafeCritical] // auto-generated

View File

@@ -6,19 +6,20 @@
//
// <OWNER>[....]</OWNER>
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
namespace System.Threading
{
using System;
using System.Security;
using System.Security.Permissions;
using Microsoft.Win32;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
using System.Diagnostics.Contracts;
using System.Diagnostics.Tracing;
using Microsoft.Win32.SafeHandles;
@@ -84,7 +85,7 @@ namespace System.Threading
// note: QueryUnbiasedInterruptTime is apparently not supported on CoreSystem currently.
// Presumably this will be a problem. Will follow up with Windows team, but for now this is diabled
// for CoreSystem builds.
#if !FEATURE_PAL && !FEATURE_CORESYSTEM
#if !FEATURE_PAL && !FEATURE_CORESYSTEM && !MONO
if (Environment.IsWindows8OrAbove)
{
ulong time100ns;
@@ -208,19 +209,19 @@ namespace System.Threading
[System.Security.SecurityCritical]
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[SuppressUnmanagedCodeSecurity]
static extern AppDomainTimerSafeHandle CreateAppDomainTimer(uint dueTime);
[System.Security.SecurityCritical]
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[SuppressUnmanagedCodeSecurity]
static extern bool ChangeAppDomainTimer(AppDomainTimerSafeHandle handle, uint dueTime);
[System.Security.SecurityCritical]
[ResourceExposure(ResourceScope.None)]
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[SuppressUnmanagedCodeSecurity]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
static extern bool DeleteAppDomainTimer(IntPtr handle);
@@ -577,7 +578,7 @@ namespace System.Threading
}
else
{
#if !FEATURE_CORECLR
#if !FEATURE_CORECLR && !MONO
if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.ThreadTransfer))
FrameworkEventSource.Log.ThreadTransferSendObj(this, 1, string.Empty, true);
#endif // !FEATURE_CORECLR
@@ -686,13 +687,17 @@ namespace System.Threading
[SecuritySafeCritical]
internal void SignalNoCallbacksRunning()
{
#if !MONO
Win32Native.SetEvent(m_notifyWhenNoCallbacksRunning.SafeWaitHandle);
#else
NativeEventCalls.SetEvent_internal (m_notifyWhenNoCallbacksRunning.SafeWaitHandle.DangerousGetHandle ());
#endif
}
[SecuritySafeCritical]
internal void CallCallback()
{
#if !FEATURE_CORECLR
#if !FEATURE_CORECLR && !MONO
if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.ThreadTransfer))
FrameworkEventSource.Log.ThreadTransferReceiveObj(this, 1, string.Empty);
#endif // !FEATURE_CORECLR

View File

@@ -15,6 +15,9 @@
**
=============================================================================*/
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
namespace System.Threading
{
using System.Threading;
@@ -23,18 +26,16 @@ namespace System.Threading
using System.Security.Permissions;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.Runtime.Versioning;
using System.Runtime.ConstrainedExecution;
using System.Diagnostics.Contracts;
using System.Diagnostics.CodeAnalysis;
using Win32Native = Microsoft.Win32.Win32Native;
[System.Runtime.InteropServices.ComVisible(true)]
#if FEATURE_REMOTING
public abstract class WaitHandle : MarshalByRefObject, IDisposable {
public abstract partial class WaitHandle : MarshalByRefObject, IDisposable {
#else // FEATURE_REMOTING
public abstract class WaitHandle : IDisposable {
public abstract partial class WaitHandle : IDisposable {
#endif // FEATURE_REMOTING
public const int WaitTimeout = 0x102;