diff options
author | Aditya Mandaleeka <adityam@microsoft.com> | 2017-06-28 15:38:13 -0700 |
---|---|---|
committer | Aditya Mandaleeka <adityam@microsoft.com> | 2017-06-28 15:38:13 -0700 |
commit | 5d4d1875f3bdaf2edea806cd0b0f60bcfe69e00e (patch) | |
tree | 951f801f6a7eea3f0369eb96cd3e20597e50ef0e /src/vm/synchronizationcontextnative.cpp | |
parent | 69afbba312e00845cc1440f0e1be2f04a41be841 (diff) | |
download | coreclr-5d4d1875f3bdaf2edea806cd0b0f60bcfe69e00e.tar.gz coreclr-5d4d1875f3bdaf2edea806cd0b0f60bcfe69e00e.tar.bz2 coreclr-5d4d1875f3bdaf2edea806cd0b0f60bcfe69e00e.zip |
Support DispatcherQueues when getting WinRT sync context.
Diffstat (limited to 'src/vm/synchronizationcontextnative.cpp')
-rw-r--r-- | src/vm/synchronizationcontextnative.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/vm/synchronizationcontextnative.cpp b/src/vm/synchronizationcontextnative.cpp index ac67f39349..03b289fc95 100644 --- a/src/vm/synchronizationcontextnative.cpp +++ b/src/vm/synchronizationcontextnative.cpp @@ -17,6 +17,7 @@ #ifdef FEATURE_APPX #include <roapi.h> #include <windows.ui.core.h> +#include "winrtdispatcherqueue.h" #endif #include "synchronizationcontextnative.h" @@ -133,6 +134,46 @@ void* QCALLTYPE SynchronizationContextNative::GetWinRTDispatcherForCurrentThread } } + // If we didn't find a CoreDispatcher for the thread, let's see if we can get a DispatcherQueue. + if (result == NULL) + { + SafeComHolderPreemp<Windows::System::IDispatcherQueueStatics> pDispatcherQueueStatics; + { + HRESULT hr = clr::winrt::GetActivationFactory(RuntimeClass_Windows_System_DispatcherQueue, + (Windows::System::IDispatcherQueueStatics**)pDispatcherQueueStatics.GetAddr()); + + // This interface was added in RS3 along with the public DispatcherQueue support. Older + // Windows builds don't support it and will return one of two HRESULTs from the call + // to GetActivationFactory above: + // - Pre-RS2 will return REGDB_E_CLASSNOTREG since Windows.System.DispatcherQueue + // does not exist at all. + // - RS2 will return E_NOINTERFACE since Windows.System.DispatcherQueue does exist + // in a limited fashion, but does not support the interface ID that we want. + // + // We should just return null if we see these two HRESULTs rather than throwing. + if (hr != REGDB_E_CLASSNOTREG && hr != E_NOINTERFACE) + { + IfFailThrow(hr); + } + } + + if (pDispatcherQueueStatics != NULL) + { + // + // Get the current IDispatcherQueue + // + SafeComHolderPreemp<Windows::System::IDispatcherQueue> pDispatcherQueue; + + pDispatcherQueueStatics->GetForCurrentThread(&pDispatcherQueue); + + if (pDispatcherQueue != NULL) + { + pDispatcherQueue.SuppressRelease(); + result = (void*)pDispatcherQueue; + } + } + } + END_QCALL; return result; } |