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 <thiago.macieira@intel.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2014-01-13 14:19:49 +01:00 committed by The Qt Project
parent aa7ec3cdf5
commit 894ce8aaab
4 changed files with 8 additions and 6 deletions

View File

@ -2086,7 +2086,9 @@ void QObject::deleteLater()
const char *qFlagLocation(const char *method)
{
QThreadData::current()->flaggedSignatures.store(method);
QThreadData *currentThreadData = QThreadData::current(false);
if (currentThreadData != 0)
currentThreadData->flaggedSignatures.store(method);
return method;
}

View File

@ -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; }

View File

@ -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);

View File

@ -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<QThreadData *>(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.