summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-10-08 10:56:25 +0200
committerLiang Qi <liang.qi@qt.io>2018-10-08 10:56:25 +0200
commit7344987c20d13710af89300f9b39e06397ec592a (patch)
tree4c12e46adefd3aee9d2ce479923fe56bab483764 /src/corelib/thread
parent8ad5967793f43bda2c38e3f9dddd3d2b6fef5390 (diff)
parent29208fa07c1b9f656ea2535696828385b7832226 (diff)
Merge remote-tracking branch 'origin/5.12' into dev
Conflicts: src/widgets/styles/qstylesheetstyle.cpp Change-Id: I3a503b44ae413fbc0a90f4af70b8f84daffd86ad
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthread_p.h3
-rw-r--r--src/corelib/thread/qthread_win.cpp35
2 files changed, 36 insertions, 2 deletions
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index 64e3f33191..7d9442ab79 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -243,6 +243,9 @@ public:
~QThreadData();
static Q_AUTOTEST_EXPORT QThreadData *current(bool createIfNecessary = true);
+#ifdef Q_OS_WINRT
+ static void setMainThread();
+#endif
static void clearCurrentThreadData();
static QThreadData *get2(QThread *thread)
{ Q_ASSERT_X(thread != 0, "QThread", "internal error"); return thread->d_func()->data; }
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index eebaf90d9b..e04d27d7b6 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -140,11 +140,15 @@ QThreadData *QThreadData::current(bool createIfNecessary)
threadData->isAdopted = true;
threadData->threadId.store(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId())));
+#ifndef Q_OS_WINRT
if (!QCoreApplicationPrivate::theMainThread) {
QCoreApplicationPrivate::theMainThread = threadData->thread.load();
- // TODO: is there a way to reflect the branch's behavior using
- // WinRT API?
} else {
+#else
+ // for winrt the main thread is set explicitly in QCoreApplication's constructor as the
+ // native main thread (Xaml thread) is not Qt's main thread.
+ {
+#endif
HANDLE realHandle = INVALID_HANDLE_VALUE;
DuplicateHandle(GetCurrentProcess(),
GetCurrentThread(),
@@ -159,6 +163,33 @@ QThreadData *QThreadData::current(bool createIfNecessary)
return threadData;
}
+#ifdef Q_OS_WINRT
+void QThreadData::setMainThread()
+{
+ Q_ASSERT(!QCoreApplicationPrivate::theMainThread);
+ qt_create_tls();
+ QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index));
+ if (!threadData) {
+ threadData = new QThreadData;
+ // This needs to be called prior to new AdoptedThread() to
+ // avoid recursion.
+ TlsSetValue(qt_current_thread_data_tls_index, threadData);
+ QT_TRY {
+ threadData->thread = new QAdoptedThread(threadData);
+ } QT_CATCH(...) {
+ TlsSetValue(qt_current_thread_data_tls_index, 0);
+ threadData->deref();
+ threadData = 0;
+ QT_RETHROW;
+ }
+ threadData->deref();
+ threadData->isAdopted = true;
+ threadData->threadId.store(reinterpret_cast<Qt::HANDLE>(quintptr(GetCurrentThreadId())));
+ }
+ QCoreApplicationPrivate::theMainThread = threadData->thread.load();
+}
+#endif
+
void QAdoptedThread::init()
{
d_func()->handle = GetCurrentThread();