diff options
author | Marek Safar <marek.safar@gmail.com> | 2019-02-05 04:43:10 +0100 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2019-02-04 19:43:10 -0800 |
commit | 382dbe4ba82f57a138484e0c5052c3b8606c1294 (patch) | |
tree | 4e220d0a0e3198678829836df034e8039e1697a2 /src | |
parent | 7e20b6fa7b2253511b6f0a7d76c955360e040df6 (diff) | |
download | coreclr-382dbe4ba82f57a138484e0c5052c3b8606c1294.tar.gz coreclr-382dbe4ba82f57a138484e0c5052c3b8606c1294.tar.bz2 coreclr-382dbe4ba82f57a138484e0c5052c3b8606c1294.zip |
Move SynchronizationContext to shared partition (#22389)
* Move SynchronizationContext to shared partition
* Move WaitHelperNative to WaitHandle
Diffstat (limited to 'src')
-rw-r--r-- | src/System.Private.CoreLib/System.Private.CoreLib.csproj | 5 | ||||
-rw-r--r-- | src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems | 1 | ||||
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs | 64 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs | 14 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs | 77 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.cs | 227 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs | 3 | ||||
-rw-r--r-- | src/vm/comwaithandle.cpp | 26 | ||||
-rw-r--r-- | src/vm/comwaithandle.h | 1 | ||||
-rw-r--r-- | src/vm/ecalllist.h | 2 | ||||
-rw-r--r-- | src/vm/mscorlib.h | 2 | ||||
-rw-r--r-- | src/vm/object.h | 9 | ||||
-rw-r--r-- | src/vm/synchronizationcontextnative.cpp | 29 | ||||
-rw-r--r-- | src/vm/synchronizationcontextnative.h | 2 |
14 files changed, 195 insertions, 267 deletions
diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj index d8c80799c0..7451445ac3 100644 --- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -268,7 +268,7 @@ <Compile Include="$(BclSourcesRoot)\System\Threading\Interlocked.cs" /> <Compile Include="$(BclSourcesRoot)\System\Threading\Monitor.cs" /> <Compile Include="$(BclSourcesRoot)\System\Threading\Overlapped.cs" /> - <Compile Include="$(BclSourcesRoot)\System\Threading\SynchronizationContext.cs" /> + <Compile Include="$(BclSourcesRoot)\System\Threading\SynchronizationContext.CoreCLR.cs" /> <Compile Include="$(BclSourcesRoot)\System\Threading\Thread.cs" /> <Compile Include="$(BclSourcesRoot)\System\Threading\ThreadPool.CoreCLR.cs" /> <Compile Include="$(BclSourcesRoot)\System\Threading\Timer.CoreCLR.cs" /> @@ -367,6 +367,9 @@ <Compile Include="$(BclSourcesRoot)\System\Globalization\GlobalizationMode.Windows.cs" /> <Compile Include="$(BclSourcesRoot)\System\Threading\ClrThreadPoolBoundHandle.Windows.cs" /> </ItemGroup> + <ItemGroup Condition="'$(FeatureAppX)' == 'true'"> + <Compile Include="$(BclSourcesRoot)\System\Threading\SynchronizationContext.Uap.cs" /> + </ItemGroup> <ItemGroup> <!-- These files are also added to CoreLib.Shared.projitems, but they don't show up in diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index 1fe9b28f69..f2a0bf096c 100644 --- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -788,6 +788,7 @@ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SendOrPostCallback.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SpinLock.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SpinWait.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SynchronizationContext.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SynchronizationLockException.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadLocal.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\AsyncCausalityTracerConstants.cs" /> diff --git a/src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs b/src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs new file mode 100644 index 0000000000..33e025dbb1 --- /dev/null +++ b/src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs @@ -0,0 +1,64 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Thread = Internal.Runtime.Augments.RuntimeThread; + +namespace System.Threading +{ + public partial class SynchronizationContext + { + private bool _requireWaitNotification; + + public SynchronizationContext() + { + } + +#if !FEATURE_APPX && !ENABLE_WINRT + public static SynchronizationContext Current => Thread.CurrentThread.SynchronizationContext; +#endif + + protected void SetWaitNotificationRequired() => _requireWaitNotification = true; + + public bool IsWaitNotificationRequired() => _requireWaitNotification; + + public virtual void Send(SendOrPostCallback d, object state) => d(state); + + public virtual void Post(SendOrPostCallback d, object state) => ThreadPool.QueueUserWorkItem(s => s.d(s.state), (d, state), preferLocal: false); + + /// <summary> + /// Optional override for subclasses, for responding to notification that operation is starting. + /// </summary> + public virtual void OperationStarted() + { + } + + /// <summary> + /// Optional override for subclasses, for responding to notification that operation has completed. + /// </summary> + public virtual void OperationCompleted() + { + } + + [CLSCompliant(false)] + public virtual int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) + { + return WaitHelper(waitHandles, waitAll, millisecondsTimeout); + } + + [CLSCompliant(false)] + protected static int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) + { + if (waitHandles == null) + { + throw new ArgumentNullException(nameof(waitHandles)); + } + + return WaitHandle.WaitMultipleIgnoringSyncContext(waitHandles, waitAll, millisecondsTimeout); + } + + public static void SetSynchronizationContext(SynchronizationContext syncContext) => Thread.CurrentThread.SynchronizationContext = syncContext; + + public virtual SynchronizationContext CreateCopy() => new SynchronizationContext(); + } +} diff --git a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs new file mode 100644 index 0000000000..e26d9b7b70 --- /dev/null +++ b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Threading +{ + public partial class SynchronizationContext + { + private static int InvokeWaitMethodHelper(SynchronizationContext syncContext, IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) + { + return syncContext.Wait(waitHandles, waitAll, millisecondsTimeout); + } + } +} diff --git a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs new file mode 100644 index 0000000000..69f6f95d25 --- /dev/null +++ b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; +using System.Reflection; +using System.Diagnostics; + +namespace System.Threading +{ + public partial class SynchronizationContext + { + public static SynchronizationContext Current + { + get + { + SynchronizationContext context = Thread.CurrentThread.SynchronizationContext; + + if (context == null && ApplicationModel.IsUap) + context = GetWinRTContext(); + + return context; + } + } + + private static SynchronizationContext GetWinRTContext() + { + Debug.Assert(Environment.IsWinRTSupported); + Debug.Assert(ApplicationModel.IsUap); + + // + // We call into the VM to get the dispatcher. This is because: + // + // a) We cannot call the WinRT APIs directly from mscorlib, because we don't have the fancy projections here. + // b) We cannot call into System.Runtime.WindowsRuntime here, because we don't want to load that assembly + // into processes that don't need it (for performance reasons). + // + // So, we check the VM to see if the current thread has a dispatcher; if it does, we pass that along to + // System.Runtime.WindowsRuntime to get a corresponding SynchronizationContext. + // + object dispatcher = GetWinRTDispatcherForCurrentThread(); + if (dispatcher != null) + return GetWinRTSynchronizationContext(dispatcher); + + return null; + } + + private static Func<object, SynchronizationContext> s_createSynchronizationContextDelegate; + + private static SynchronizationContext GetWinRTSynchronizationContext(object dispatcher) + { + // + // Since we can't directly reference System.Runtime.WindowsRuntime from mscorlib, we have to get the factory via reflection. + // It would be better if we could just implement WinRTSynchronizationContextFactory in mscorlib, but we can't, because + // we can do very little with WinRT stuff in mscorlib. + // + Func<object, SynchronizationContext> createSynchronizationContextDelegate = s_createSynchronizationContextDelegate; + if (createSynchronizationContextDelegate == null) + { + Type factoryType = Type.GetType("System.Threading.WinRTSynchronizationContextFactory, System.Runtime.WindowsRuntime", throwOnError: true); + + // Create an instance delegate for the Create static method + MethodInfo createMethodInfo = factoryType.GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); + createSynchronizationContextDelegate = (Func<object, SynchronizationContext>)Delegate.CreateDelegate(typeof(Func<object, SynchronizationContext>), createMethodInfo, /* throwOnBindFailure */ true); + + s_createSynchronizationContextDelegate = createSynchronizationContextDelegate; + } + + return s_createSynchronizationContextDelegate(dispatcher); + } + + [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] + [return: MarshalAs(UnmanagedType.Interface)] + private static extern object GetWinRTDispatcherForCurrentThread(); + } +} diff --git a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.cs b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.cs deleted file mode 100644 index a1336cb95e..0000000000 --- a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.cs +++ /dev/null @@ -1,227 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. -/*============================================================ -** -** -** -** Purpose: Capture synchronization semantics for asynchronous callbacks -** -** -===========================================================*/ - -namespace System.Threading -{ - using Microsoft.Win32.SafeHandles; - using System.Runtime.InteropServices; - using System.Runtime.CompilerServices; - using System.Runtime.ExceptionServices; - using System.Runtime; - using System.Runtime.Versioning; - using System.Runtime.ConstrainedExecution; - using System.Reflection; - using System.Security; - using System.Diagnostics; - using System.Diagnostics.CodeAnalysis; - - - [Flags] - internal enum SynchronizationContextProperties - { - None = 0, - RequireWaitNotification = 0x1 - }; - - public class SynchronizationContext - { - private SynchronizationContextProperties _props = SynchronizationContextProperties.None; - - public SynchronizationContext() - { - } - - - // helper delegate to statically bind to Wait method - private delegate int WaitDelegate(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout); - - private static Type s_cachedPreparedType1; - private static Type s_cachedPreparedType2; - private static Type s_cachedPreparedType3; - private static Type s_cachedPreparedType4; - private static Type s_cachedPreparedType5; - - // protected so that only the derived sync context class can enable these flags - [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "We never dereference s_cachedPreparedType*, so ordering is unimportant")] - protected void SetWaitNotificationRequired() - { - // - // Prepare the method so that it can be called in a reliable fashion when a wait is needed. - // This will obviously only make the Wait reliable if the Wait method is itself reliable. The only thing - // preparing the method here does is to ensure there is no failure point before the method execution begins. - // - // Preparing the method in this way is quite expensive, but only needs to be done once per type, per AppDomain. - // So we keep track of a few types we've already prepared in this AD. It is uncommon to have more than - // a few SynchronizationContext implementations, so we only cache the first five we encounter; this lets - // our cache be much faster than a more general cache might be. This is important, because this - // is a *very* hot code path for many WPF and WinForms apps. - // - Type type = this.GetType(); - if (s_cachedPreparedType1 != type && - s_cachedPreparedType2 != type && - s_cachedPreparedType3 != type && - s_cachedPreparedType4 != type && - s_cachedPreparedType5 != type) - { - RuntimeHelpers.PrepareDelegate(new WaitDelegate(this.Wait)); - - if (s_cachedPreparedType1 == null) s_cachedPreparedType1 = type; - else if (s_cachedPreparedType2 == null) s_cachedPreparedType2 = type; - else if (s_cachedPreparedType3 == null) s_cachedPreparedType3 = type; - else if (s_cachedPreparedType4 == null) s_cachedPreparedType4 = type; - else if (s_cachedPreparedType5 == null) s_cachedPreparedType5 = type; - } - - _props |= SynchronizationContextProperties.RequireWaitNotification; - } - - public bool IsWaitNotificationRequired() - { - return ((_props & SynchronizationContextProperties.RequireWaitNotification) != 0); - } - - - public virtual void Send(SendOrPostCallback d, object state) - { - d(state); - } - - public virtual void Post(SendOrPostCallback d, object state) - { - ThreadPool.QueueUserWorkItem(s => s.d(s.state), (d, state), preferLocal: false); - } - - - /// <summary> - /// Optional override for subclasses, for responding to notification that operation is starting. - /// </summary> - public virtual void OperationStarted() - { - } - - /// <summary> - /// Optional override for subclasses, for responding to notification that operation has completed. - /// </summary> - public virtual void OperationCompleted() - { - } - - // Method called when the CLR does a wait operation - [CLSCompliant(false)] - 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)] - protected static int WaitHelper(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) - { - if (waitHandles == null) - { - throw new ArgumentNullException(nameof(waitHandles)); - } - - return WaitHelperNative(waitHandles, waitAll, millisecondsTimeout); - } - - // Static helper to which the above method can delegate to in order to get the default - // COM behavior. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern int WaitHelperNative(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout); - - public static void SetSynchronizationContext(SynchronizationContext syncContext) - { - Thread.CurrentThread.SynchronizationContext = syncContext; - } - - public static SynchronizationContext Current - { - get - { - SynchronizationContext context = Thread.CurrentThread.SynchronizationContext; - -#if FEATURE_APPX - if (context == null && ApplicationModel.IsUap) - context = GetWinRTContext(); -#endif - - return context; - } - } - -#if FEATURE_APPX - private static SynchronizationContext GetWinRTContext() - { - Debug.Assert(Environment.IsWinRTSupported); - Debug.Assert(ApplicationModel.IsUap); - - // - // We call into the VM to get the dispatcher. This is because: - // - // a) We cannot call the WinRT APIs directly from mscorlib, because we don't have the fancy projections here. - // b) We cannot call into System.Runtime.WindowsRuntime here, because we don't want to load that assembly - // into processes that don't need it (for performance reasons). - // - // So, we check the VM to see if the current thread has a dispatcher; if it does, we pass that along to - // System.Runtime.WindowsRuntime to get a corresponding SynchronizationContext. - // - object dispatcher = GetWinRTDispatcherForCurrentThread(); - if (dispatcher != null) - return GetWinRTSynchronizationContext(dispatcher); - - return null; - } - - private static Func<object, SynchronizationContext> s_createSynchronizationContextDelegate = null; - - private static SynchronizationContext GetWinRTSynchronizationContext(object dispatcher) - { - // - // Since we can't directly reference System.Runtime.WindowsRuntime from mscorlib, we have to get the factory via reflection. - // It would be better if we could just implement WinRTSynchronizationContextFactory in mscorlib, but we can't, because - // we can do very little with WinRT stuff in mscorlib. - // - Func<object, SynchronizationContext> createSynchronizationContextDelegate = s_createSynchronizationContextDelegate; - if (createSynchronizationContextDelegate == null) - { - Type factoryType = Type.GetType("System.Threading.WinRTSynchronizationContextFactory, System.Runtime.WindowsRuntime", throwOnError: true); - - // Create an instance delegate for the Create static method - MethodInfo createMethodInfo = factoryType.GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); - createSynchronizationContextDelegate = (Func<object, SynchronizationContext>)Delegate.CreateDelegate(typeof(Func<object, SynchronizationContext>), createMethodInfo, /* throwOnBindFailure */ true); - - s_createSynchronizationContextDelegate = createSynchronizationContextDelegate; - } - - return s_createSynchronizationContextDelegate(dispatcher); - } - - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [return: MarshalAs(UnmanagedType.Interface)] - private static extern object GetWinRTDispatcherForCurrentThread(); -#endif //FEATURE_APPX - - - // helper to Clone this SynchronizationContext, - public virtual SynchronizationContext CreateCopy() - { - // the CLR dummy has an empty clone function - no member data - return new SynchronizationContext(); - } - - private static int InvokeWaitMethodHelper(SynchronizationContext syncContext, IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout) - { - return syncContext.Wait(waitHandles, waitAll, millisecondsTimeout); - } - } -} diff --git a/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs b/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs index 6f3f9d220a..83c5269cbb 100644 --- a/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs +++ b/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs @@ -221,6 +221,9 @@ namespace System.Threading [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern int WaitMultiple(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext, bool WaitAll); + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern int WaitMultipleIgnoringSyncContext(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout); + public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) { if (waitHandles == null) diff --git a/src/vm/comwaithandle.cpp b/src/vm/comwaithandle.cpp index 935a8f031a..48dab31fcd 100644 --- a/src/vm/comwaithandle.cpp +++ b/src/vm/comwaithandle.cpp @@ -311,3 +311,29 @@ FCIMPL5(INT32, WaitHandleNative::CorSignalAndWaitOneNative, SafeHandle* safeWait return retVal; } FCIMPLEND + +FCIMPL3(DWORD, WaitHandleNative::WaitHelper, PTRArray *handleArrayUNSAFE, CLR_BOOL waitAll, DWORD millis) +{ + FCALL_CONTRACT; + + DWORD ret = 0; + + PTRARRAYREF handleArrayObj = (PTRARRAYREF) handleArrayUNSAFE; + HELPER_METHOD_FRAME_BEGIN_RET_1(handleArrayObj); + + CQuickArray<HANDLE> qbHandles; + int cHandles = handleArrayObj->GetNumComponents(); + + // Since DoAppropriateWait could cause a GC, we need to copy the handles to an unmanaged block + // of memory to ensure they aren't relocated during the call to DoAppropriateWait. + qbHandles.AllocThrows(cHandles); + memcpy(qbHandles.Ptr(), handleArrayObj->GetDataPtr(), cHandles * sizeof(HANDLE)); + + Thread * pThread = GetThread(); + ret = pThread->DoAppropriateWait(cHandles, qbHandles.Ptr(), waitAll, millis, + (WaitMode)(WaitMode_Alertable | WaitMode_IgnoreSyncCtx)); + + HELPER_METHOD_FRAME_END(); + return ret; +} +FCIMPLEND diff --git a/src/vm/comwaithandle.h b/src/vm/comwaithandle.h index 9c27460080..df08a10733 100644 --- a/src/vm/comwaithandle.h +++ b/src/vm/comwaithandle.h @@ -22,5 +22,6 @@ public: static FCDECL4(INT32, CorWaitOneNative, SafeHandle* safeWaitHandleUNSAFE, INT32 timeout, CLR_BOOL hasThreadAffinity, CLR_BOOL exitContext); static FCDECL4(INT32, CorWaitMultipleNative, Object* waitObjectsUNSAFE, INT32 timeout, CLR_BOOL exitContext, CLR_BOOL waitForAll); static FCDECL5(INT32, CorSignalAndWaitOneNative, SafeHandle* safeWaitHandleSignalUNSAFE, SafeHandle* safeWaitHandleWaitUNSAFE, INT32 timeout, CLR_BOOL hasThreadAffinity, CLR_BOOL exitContext); + static FCDECL3(DWORD, WaitHelper, PTRArray *handleArrayUNSAFE, CLR_BOOL waitAll, DWORD millis); }; #endif diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h index bef2de9674..9a1d6922e8 100644 --- a/src/vm/ecalllist.h +++ b/src/vm/ecalllist.h @@ -716,6 +716,7 @@ FCFuncStart(gWaitHandleFuncs) FCFuncElement("WaitOneNative", WaitHandleNative::CorWaitOneNative) FCFuncElement("WaitMultiple", WaitHandleNative::CorWaitMultipleNative) FCFuncElement("SignalAndWaitOne", WaitHandleNative::CorSignalAndWaitOneNative) + FCFuncElement("WaitMultipleIgnoringSyncContext", WaitHandleNative::WaitHelper) FCFuncEnd() #ifdef FEATURE_COMINTEROP @@ -949,7 +950,6 @@ FCFuncStart(gRuntimeHelpers) FCFuncEnd() FCFuncStart(gContextSynchronizationFuncs) - FCFuncElement("WaitHelperNative", SynchronizationContextNative::WaitHelper) #ifdef FEATURE_APPX QCFuncElement("GetWinRTDispatcherForCurrentThread", SynchronizationContextNative::GetWinRTDispatcherForCurrentThread) #endif diff --git a/src/vm/mscorlib.h b/src/vm/mscorlib.h index 81c21f2bde..56aa94fb62 100644 --- a/src/vm/mscorlib.h +++ b/src/vm/mscorlib.h @@ -821,7 +821,7 @@ DEFINE_METHOD(STRING_BUILDER, REPLACE_BUFFER_ANSI_INTERNAL,ReplaceBufferAn DEFINE_CLASS(STRONG_NAME_KEY_PAIR, Reflection, StrongNameKeyPair) DEFINE_CLASS_U(Threading, SynchronizationContext, SynchronizationContextObject) -DEFINE_FIELD_U(_props, SynchronizationContextObject, _props) +DEFINE_FIELD_U(_requireWaitNotification, SynchronizationContextObject, _requireWaitNotification) DEFINE_CLASS(SYNCHRONIZATION_CONTEXT, Threading, SynchronizationContext) DEFINE_METHOD(SYNCHRONIZATION_CONTEXT, INVOKE_WAIT_METHOD_HELPER, InvokeWaitMethodHelper, SM_SyncCtx_ArrIntPtr_Bool_Int_RetInt) diff --git a/src/vm/object.h b/src/vm/object.h index 54ccd4c650..d3a3af3cd9 100644 --- a/src/vm/object.h +++ b/src/vm/object.h @@ -1334,7 +1334,6 @@ typedef SafeHandle * SAFEHANDLEREF; -#define SYNCCTXPROPS_REQUIRESWAITNOTIFICATION 0x1 // Keep in sync with SynchronizationContext.cs SynchronizationContextFlags class ThreadBaseObject; class SynchronizationContextObject: public Object { @@ -1344,14 +1343,12 @@ private: // add or change these field you must also change the managed code so that // it matches these. This is necessary so that the object is the proper // size. - INT32 _props; + CLR_BOOL _requireWaitNotification; public: - BOOL IsWaitNotificationRequired() + BOOL IsWaitNotificationRequired() const { LIMITED_METHOD_CONTRACT; - if ((_props & SYNCCTXPROPS_REQUIRESWAITNOTIFICATION) != 0) - return TRUE; - return FALSE; + return _requireWaitNotification; } }; diff --git a/src/vm/synchronizationcontextnative.cpp b/src/vm/synchronizationcontextnative.cpp index 03b289fc95..654f69e3ab 100644 --- a/src/vm/synchronizationcontextnative.cpp +++ b/src/vm/synchronizationcontextnative.cpp @@ -18,37 +18,8 @@ #include <roapi.h> #include <windows.ui.core.h> #include "winrtdispatcherqueue.h" -#endif #include "synchronizationcontextnative.h" - -FCIMPL3(DWORD, SynchronizationContextNative::WaitHelper, PTRArray *handleArrayUNSAFE, CLR_BOOL waitAll, DWORD millis) -{ - FCALL_CONTRACT; - - DWORD ret = 0; - - PTRARRAYREF handleArrayObj = (PTRARRAYREF) handleArrayUNSAFE; - HELPER_METHOD_FRAME_BEGIN_RET_1(handleArrayObj); - - CQuickArray<HANDLE> qbHandles; - int cHandles = handleArrayObj->GetNumComponents(); - - // Since DoAppropriateWait could cause a GC, we need to copy the handles to an unmanaged block - // of memory to ensure they aren't relocated during the call to DoAppropriateWait. - qbHandles.AllocThrows(cHandles); - memcpy(qbHandles.Ptr(), handleArrayObj->GetDataPtr(), cHandles * sizeof(HANDLE)); - - Thread * pThread = GetThread(); - ret = pThread->DoAppropriateWait(cHandles, qbHandles.Ptr(), waitAll, millis, - (WaitMode)(WaitMode_Alertable | WaitMode_IgnoreSyncCtx)); - - HELPER_METHOD_FRAME_END(); - return ret; -} -FCIMPLEND -#ifdef FEATURE_APPX - Volatile<ABI::Windows::UI::Core::ICoreWindowStatic*> g_pICoreWindowStatic; void* QCALLTYPE SynchronizationContextNative::GetWinRTDispatcherForCurrentThread() diff --git a/src/vm/synchronizationcontextnative.h b/src/vm/synchronizationcontextnative.h index 917d3a0afb..a89579ff61 100644 --- a/src/vm/synchronizationcontextnative.h +++ b/src/vm/synchronizationcontextnative.h @@ -19,8 +19,6 @@ class SynchronizationContextNative { public: - static FCDECL3(DWORD, WaitHelper, PTRArray *handleArrayUNSAFE, CLR_BOOL waitAll, DWORD millis); - #ifdef FEATURE_APPX static void* QCALLTYPE GetWinRTDispatcherForCurrentThread(); static void Cleanup(); |