From 894ce8aaab8d3319a704deb73cb5109d092df0aa Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 13 Jan 2014 14:19:49 +0100 Subject: Android: Don't register main thread on loading library When building with debug, all SLOT or SIGNAL macros will expand to a function call, and then function will call QThreadData::current(), which will set QCoreApplication::theMainThread if it has not already been done. Since Qt Widgets has these macros in the static initialization of the library, we would register the Android main thread as the main thread of Qt, which would mean that the actual application object was created on a different thread than the main thread. This caused warnings to appear, and also triggered a race condition which caused widget applications to sometimes show a black screen instead of content on startup when run with the OpenGL plugin. Task-number: QTBUG-35048 Change-Id: Ie8979f5e7cd5662f8d7dd276de9f94f27cc120b5 Reviewed-by: Thiago Macieira --- src/corelib/thread/qthread_p.h | 2 +- src/corelib/thread/qthread_unix.cpp | 4 ++-- src/corelib/thread/qthread_win.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/corelib/thread') diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index 8429e41433..fce84e881b 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -223,7 +223,7 @@ public: QThreadData(int initialRefCount = 1); ~QThreadData(); - static QThreadData *current(); + static QThreadData *current(bool createIfNecessary = true); 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_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 15558cb148..b838cb4b28 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -215,10 +215,10 @@ void QThreadData::clearCurrentThreadData() clear_thread_data(); } -QThreadData *QThreadData::current() +QThreadData *QThreadData::current(bool createIfNecessary) { QThreadData *data = get_thread_data(); - if (!data) { + if (!data && createIfNecessary) { data = new QThreadData; QT_TRY { set_thread_data(data); diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 037343c996..865b1e6af5 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -101,11 +101,11 @@ void QThreadData::clearCurrentThreadData() TlsSetValue(qt_current_thread_data_tls_index, 0); } -QThreadData *QThreadData::current() +QThreadData *QThreadData::current(bool createIfNecessary) { qt_create_tls(); QThreadData *threadData = reinterpret_cast(TlsGetValue(qt_current_thread_data_tls_index)); - if (!threadData) { + if (!threadData && createIfNecessary) { threadData = new QThreadData; // This needs to be called prior to new AdoptedThread() to // avoid recursion. -- cgit v1.2.3