summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@theqtcompany.com>2015-06-10 12:48:17 +0200
committerOliver Wolff <oliver.wolff@theqtcompany.com>2015-06-23 05:47:14 +0000
commitbf24838c3344f009f9fe40f596a4eab798f071b3 (patch)
treea946c012f36cb037a9f412ebe0fbafea0f949094 /src/corelib/kernel
parent4ce05c608410f2574e92bc6c65ad5c830b66b12f (diff)
Use qthread_win.cpp for WinRT as well
Since of Windows (Phone) 8.1 most of the desktop's thread functionality is also available, so we might be able to share the code and get rid of the extra implementation for WinRT. Task-number: QTBUG-43837 Change-Id: I0ce907cd94899834527f88c70e1e395bafdb14b3 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qeventdispatcher_winrt.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp
index 1509996199..0274f35dba 100644
--- a/src/corelib/kernel/qeventdispatcher_winrt.cpp
+++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp
@@ -144,7 +144,10 @@ private:
IID_PPV_ARGS(&application));
RETURN_VOID_IF_FAILED("Failed to get the application factory");
- ComPtr<ICoreApplicationView> view;
+ static ComPtr<ICoreApplicationView> view;
+ if (view)
+ return;
+
hr = application->get_MainView(&view);
RETURN_VOID_IF_FAILED("Failed to get the main view");
@@ -166,13 +169,6 @@ QEventDispatcherWinRT::QEventDispatcherWinRT(QObject *parent)
{
Q_D(QEventDispatcherWinRT);
- // Special treatment for the WinMain thread, as it is created before the UI
- static bool firstThread = true;
- if (firstThread) {
- firstThread = false;
- return;
- }
-
d->fetchCoreDispatcher();
}
@@ -212,6 +208,7 @@ bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags)
DWORD waitResult = WaitForMultipleObjectsEx(timerHandles.count(), timerHandles.constData(), FALSE, 1, TRUE);
if (waitResult >= WAIT_OBJECT_0 && waitResult < WAIT_OBJECT_0 + timerHandles.count()) {
const HANDLE handle = timerHandles.value(waitResult - WAIT_OBJECT_0);
+ ResetEvent(handle);
const int timerId = d->timerHandleToId.value(handle);
if (timerId == INTERRUPT_HANDLE)
break;
@@ -288,8 +285,8 @@ void QEventDispatcherWinRT::registerTimer(int timerId, int interval, Qt::TimerTy
TimeSpan period;
period.Duration = interval ? (interval * 10000) : 1; // TimeSpan is based on 100-nanosecond units
IThreadPoolTimer *timer;
- const HANDLE handle = CreateEventEx(NULL, NULL, NULL, SYNCHRONIZE|EVENT_MODIFY_STATE);
- const HANDLE cancelHandle = CreateEventEx(NULL, NULL, NULL, SYNCHRONIZE|EVENT_MODIFY_STATE);
+ const HANDLE handle = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, SYNCHRONIZE | EVENT_MODIFY_STATE);
+ const HANDLE cancelHandle = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, SYNCHRONIZE|EVENT_MODIFY_STATE);
HRESULT hr = d->timerFactory->CreatePeriodicTimerWithCompletion(
Callback<ITimerElapsedHandler>([handle, cancelHandle](IThreadPoolTimer *timer) {
DWORD cancelResult = WaitForSingleObjectEx(cancelHandle, 0, TRUE);
@@ -486,7 +483,9 @@ bool QEventDispatcherWinRT::event(QEvent *e)
QEventDispatcherWinRTPrivate::QEventDispatcherWinRTPrivate()
{
- CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+ const bool isGuiThread = QCoreApplication::instance() &&
+ QThread::currentThread() == QCoreApplication::instance()->thread();
+ CoInitializeEx(NULL, isGuiThread ? COINIT_APARTMENTTHREADED : COINIT_MULTITHREADED);
HRESULT hr;
hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_System_Threading_ThreadPoolTimer).Get(), &timerFactory);
Q_ASSERT_SUCCEEDED(hr);