Skip to content

Commit 8a7f7fe

Browse files
committed
eliminate main thread store
fixes RCC runtime crash on NetBSD Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
1 parent 2635c8a commit 8a7f7fe

7 files changed

+3
-55
lines changed

src/core/kernel/qcoreapplication.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,6 @@ struct QCoreApplicationData {
169169
~QCoreApplicationData() {
170170
#ifndef QT_NO_LIBRARY
171171
delete app_libpaths;
172-
#endif
173-
#ifndef QT_NO_QOBJECT
174-
// cleanup the QAdoptedThread created for the main() thread
175-
if (QCoreApplicationPrivate::theMainThread) {
176-
QThreadData *data = QThreadData::get2(QCoreApplicationPrivate::theMainThread);
177-
data->deref(); // deletes the data and the adopted thread
178-
}
179172
#endif
180173
}
181174

@@ -200,10 +193,6 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv)
200193
argv = (char **)&empty; // ouch! careful with QCoreApplication::argv()!
201194
}
202195
QCoreApplicationPrivate::is_app_closing = false;
203-
204-
// note: this call to QThread::currentThread() may end up setting theMainThread!
205-
if (Q_UNLIKELY(QThread::currentThread() != theMainThread))
206-
qWarning("WARNING: QApplication was not created in the main() thread.");
207196
}
208197

209198
QCoreApplicationPrivate::~QCoreApplicationPrivate()
@@ -231,8 +220,6 @@ void QCoreApplicationPrivate::createEventDispatcher()
231220
eventDispatcher = new QEventDispatcherUNIX(q);
232221
}
233222

234-
QThread *QCoreApplicationPrivate::theMainThread = Q_NULLPTR;
235-
236223
#if !defined (QT_NO_DEBUG)
237224
void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver)
238225
{

src/core/kernel/qcoreapplication_p.h

-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ class Q_CORE_EXPORT QCoreApplicationPrivate : public QObjectPrivate
7878
virtual void createEventDispatcher();
7979
static void removePostedEvent(QEvent *);
8080

81-
static QThread *theMainThread;
82-
static inline QThread *mainThread()
83-
{ Q_ASSERT(theMainThread != 0); return theMainThread; }
8481
static bool checkInstance(const char *method);
8582
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data);
8683

src/core/plugin/qfactoryloader.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ QFactoryLoader::QFactoryLoader(const char *iid,
8080
Qt::CaseSensitivity cs)
8181
: QObject(*new QFactoryLoaderPrivate)
8282
{
83-
moveToThread(QCoreApplicationPrivate::mainThread());
8483
Q_D(QFactoryLoader);
8584
d->iid = iid;
8685
d->cs = cs;
@@ -223,11 +222,7 @@ QObject *QFactoryLoader::instance(const QString &key) const
223222
QString lowered = d->cs ? key : key.toLower();
224223
if (QLibraryPrivate* library = d->keyMap.value(lowered)) {
225224
if (library->instance || library->loadPlugin()) {
226-
if (QObject *obj = library->instance()) {
227-
if (obj && !obj->parent())
228-
obj->moveToThread(QCoreApplicationPrivate::mainThread());
229-
return obj;
230-
}
225+
return library->instance();
231226
}
232227
}
233228
return 0;

src/core/thread/qthread.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,6 @@ QThreadData::~QThreadData()
6161
{
6262
Q_ASSERT(_ref == 0);
6363

64-
// In the odd case that Qt is running on a secondary thread, the main
65-
// thread instance will have been dereffed asunder because of the deref in
66-
// QThreadData::current() and the deref in the pthread_destroy. To avoid
67-
// crashing during QCoreApplicationData's global static cleanup we need to
68-
// safeguard the main thread here.. This fix is a bit crude, but it solves
69-
// the problem...
70-
if (this->thread == QCoreApplicationPrivate::theMainThread) {
71-
QCoreApplicationPrivate::theMainThread = Q_NULLPTR;
72-
QThreadData::clearCurrentThreadData();
73-
}
74-
7564
delete thread;
7665
thread = Q_NULLPTR;
7766

src/core/thread/qthread_unix.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ QThreadData *QThreadData::current()
148148

149149
data->isAdopted = true;
150150
data->threadId = (Qt::HANDLE)pthread_self();
151-
if (!QCoreApplicationPrivate::theMainThread)
152-
QCoreApplicationPrivate::theMainThread = data->thread;
153151
}
154152
return data;
155153
}

src/network/bearer/qnetworkconfigmanager.cpp

+2-14
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
#include <QtCore/qstringlist.h>
4040
#include <QtCore/qcoreapplication.h>
4141
#include <QtCore/qmutex.h>
42-
#include <QtCore/qthread.h>
43-
#include <QtCore/qcoreapplication_p.h>
4442

4543
#ifndef QT_NO_BEARERMANAGEMENT
4644

@@ -74,18 +72,8 @@ static QNetworkConfigurationManagerPrivate *connManager()
7472
if (!(ptr = connManager_ptr.fetchAndAddAcquire(0))) {
7573
ptr = new QNetworkConfigurationManagerPrivate;
7674

77-
if (QCoreApplicationPrivate::mainThread() == QThread::currentThread()) {
78-
// right thread or no main thread yet
79-
ptr->addPostRoutine();
80-
ptr->initialize();
81-
} else {
82-
// wrong thread, we need to make the main thread do this
83-
QObject *obj = new QObject;
84-
QObject::connect(obj, SIGNAL(destroyed()), ptr, SLOT(addPostRoutine()), Qt::DirectConnection);
85-
ptr->initialize(); // this moves us to the right thread
86-
obj->moveToThread(QCoreApplicationPrivate::mainThread());
87-
obj->deleteLater();
88-
}
75+
ptr->addPostRoutine();
76+
ptr->initialize();
8977

9078
connManager_ptr.fetchAndStoreRelease(ptr);
9179
}

src/network/bearer/qnetworkconfigmanager_p.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@
3333

3434
#include "qnetworkconfigmanager_p.h"
3535
#include "qbearerplugin_p.h"
36-
3736
#include <QtCore/qfactoryloader_p.h>
38-
3937
#include <QtCore/qdebug.h>
4038
#include <QtCore/qtimer.h>
4139
#include <QtCore/qstringlist.h>
42-
#include <QtCore/qcoreapplication_p.h>
4340

4441
#ifndef QT_NO_BEARERMANAGEMENT
4542

@@ -59,7 +56,6 @@ QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate()
5956

6057
void QNetworkConfigurationManagerPrivate::initialize()
6158
{
62-
moveToThread(QCoreApplicationPrivate::mainThread()); // because cleanup() is called in main thread context.
6359
updateConfigurations();
6460
}
6561

@@ -366,8 +362,6 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations()
366362
else
367363
sessionEngines.append(engine);
368364

369-
engine->moveToThread(QCoreApplicationPrivate::mainThread());
370-
371365
connect(engine, SIGNAL(updateCompleted()),
372366
this, SLOT(updateConfigurations()),
373367
Qt::QueuedConnection);

0 commit comments

Comments
 (0)