diff options
Diffstat (limited to 'src/mscorlib/src/System/Threading/SynchronizationContext.cs')
-rw-r--r-- | src/mscorlib/src/System/Threading/SynchronizationContext.cs | 90 |
1 files changed, 20 insertions, 70 deletions
diff --git a/src/mscorlib/src/System/Threading/SynchronizationContext.cs b/src/mscorlib/src/System/Threading/SynchronizationContext.cs index a3f28d1d73..5531597229 100644 --- a/src/mscorlib/src/System/Threading/SynchronizationContext.cs +++ b/src/mscorlib/src/System/Threading/SynchronizationContext.cs @@ -24,6 +24,7 @@ namespace System.Threading using System.Runtime.ConstrainedExecution; using System.Reflection; using System.Security; + using System.Diagnostics; using System.Diagnostics.Contracts; using System.Diagnostics.CodeAnalysis; @@ -43,17 +44,12 @@ namespace System.Threading // I'd like this to be an interface, or at least an abstract class - but neither seems to play nice with FriendAccessAllowed. // [FriendAccessAllowed] - [SecurityCritical] internal class WinRTSynchronizationContextFactoryBase { - [SecurityCritical] public virtual SynchronizationContext Create(object coreDispatcher) {return null;} } #endif //FEATURE_COMINTEROP -#if !FEATURE_CORECLR - [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags =SecurityPermissionFlag.ControlPolicy|SecurityPermissionFlag.ControlEvidence)] -#endif public class SynchronizationContext { #if FEATURE_SYNCHRONIZATIONCONTEXT_WAIT @@ -76,7 +72,6 @@ namespace System.Threading static Type s_cachedPreparedType5; // protected so that only the derived sync context class can enable these flags - [System.Security.SecuritySafeCritical] // auto-generated [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "We never dereference s_cachedPreparedType*, so ordering is unimportant")] protected void SetWaitNotificationRequired() { @@ -143,39 +138,43 @@ namespace System.Threading } #if FEATURE_SYNCHRONIZATIONCONTEXT_WAIT - // Method called when the CLR does a wait operation - [System.Security.SecurityCritical] // auto-generated_required + // Method called when the CLR does a wait operation [CLSCompliant(false)] [PrePrepareMethod] public virtual int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) { + return WaitHelper(waitHandles, waitAll, millisecondsTimeout); + } + + // Method that can be called by Wait overrides + [CLSCompliant(false)] + [PrePrepareMethod] + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] + protected static int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) + { if (waitHandles == null) { - throw new ArgumentNullException("waitHandles"); + throw new ArgumentNullException(nameof(waitHandles)); } Contract.EndContractBlock(); - return WaitHelper(waitHandles, waitAll, millisecondsTimeout); + + return WaitHelperNative(waitHandles, waitAll, millisecondsTimeout); } - - // Static helper to which the above method can delegate to in order to get the default + + // Static helper to which the above method can delegate to in order to get the default // COM behavior. - [System.Security.SecurityCritical] // auto-generated_required [CLSCompliant(false)] [PrePrepareMethod] - [MethodImplAttribute(MethodImplOptions.InternalCall)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] - protected static extern int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout); + private static extern int WaitHelperNative(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout); #endif -#if FEATURE_CORECLR - - [System.Security.SecurityCritical] public static void SetSynchronizationContext(SynchronizationContext syncContext) { Thread.CurrentThread.SynchronizationContext = syncContext; } - [System.Security.SecurityCritical] public static void SetThreadStaticContext(SynchronizationContext syncContext) { Thread.CurrentThread.SynchronizationContext = syncContext; @@ -206,56 +205,11 @@ namespace System.Threading } } -#else //FEATURE_CORECLR - - // set SynchronizationContext on the current thread - [System.Security.SecurityCritical] // auto-generated_required - public static void SetSynchronizationContext(SynchronizationContext syncContext) - { - ExecutionContext ec = Thread.CurrentThread.GetMutableExecutionContext(); - ec.SynchronizationContext = syncContext; - ec.SynchronizationContextNoFlow = syncContext; - } - - // Get the current SynchronizationContext on the current thread - public static SynchronizationContext Current - { - get - { - return Thread.CurrentThread.GetExecutionContextReader().SynchronizationContext ?? GetThreadLocalContext(); - } - } - - // Get the last SynchronizationContext that was set explicitly (not flowed via ExecutionContext.Capture/Run) - internal static SynchronizationContext CurrentNoFlow - { - [FriendAccessAllowed] - get - { - return Thread.CurrentThread.GetExecutionContextReader().SynchronizationContextNoFlow ?? GetThreadLocalContext(); - } - } - - private static SynchronizationContext GetThreadLocalContext() - { - SynchronizationContext context = null; - -#if FEATURE_APPX - if (context == null && AppDomain.IsAppXModel()) - context = GetWinRTContext(); -#endif - - return context; - } - -#endif //FEATURE_CORECLR - #if FEATURE_APPX - [SecuritySafeCritical] private static SynchronizationContext GetWinRTContext() { - Contract.Assert(Environment.IsWinRTSupported); - Contract.Assert(AppDomain.IsAppXModel()); + Debug.Assert(Environment.IsWinRTSupported); + Debug.Assert(AppDomain.IsAppXModel()); // // We call into the VM to get the dispatcher. This is because: @@ -274,10 +228,8 @@ namespace System.Threading return null; } - [SecurityCritical] static WinRTSynchronizationContextFactoryBase s_winRTContextFactory; - [SecurityCritical] private static WinRTSynchronizationContextFactoryBase GetWinRTSynchronizationContextFactory() { // @@ -295,7 +247,6 @@ namespace System.Threading } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Interface)] private static extern object GetWinRTDispatcherForCurrentThread(); @@ -310,7 +261,6 @@ namespace System.Threading } #if FEATURE_SYNCHRONIZATIONCONTEXT_WAIT - [System.Security.SecurityCritical] // auto-generated private static int InvokeWaitMethodHelper(SynchronizationContext syncContext, IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) { return syncContext.Wait(waitHandles, waitAll, millisecondsTimeout); |