QThread: Centralize the creation of the event dispatcher
In some places we call startingUp(), in others we don't. It's probably ok for those that have just created an object of a given class, which knows whether the virtual call is necessary or not. But for the generic case, we do call it. Change-Id: If48c5c2e920c433298f1fffd153ee1cc75703204 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
f6425da424
commit
56d52e1f1a
@ -540,7 +540,7 @@ void QCoreApplicationPrivate::createEventDispatcher()
|
|||||||
Q_Q(QCoreApplication);
|
Q_Q(QCoreApplication);
|
||||||
QThreadData *data = QThreadData::current();
|
QThreadData *data = QThreadData::current();
|
||||||
Q_ASSERT(!data->hasEventDispatcher());
|
Q_ASSERT(!data->hasEventDispatcher());
|
||||||
eventDispatcher = QThreadPrivate::createEventDispatcher(data);
|
eventDispatcher = data->createEventDispatcher();
|
||||||
eventDispatcher->setParent(q);
|
eventDispatcher->setParent(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,10 +101,8 @@ QEventLoop::QEventLoop(QObject *parent)
|
|||||||
Q_D(QEventLoop);
|
Q_D(QEventLoop);
|
||||||
if (!QCoreApplication::instance() && QCoreApplicationPrivate::threadRequiresCoreApplication()) {
|
if (!QCoreApplication::instance() && QCoreApplicationPrivate::threadRequiresCoreApplication()) {
|
||||||
qWarning("QEventLoop: Cannot be used without QApplication");
|
qWarning("QEventLoop: Cannot be used without QApplication");
|
||||||
} else if (!d->threadData->hasEventDispatcher()) {
|
} else {
|
||||||
QAbstractEventDispatcher *eventDispatcher = QThreadPrivate::createEventDispatcher(d->threadData);
|
d->threadData->ensureEventDispatcher();
|
||||||
d->threadData->eventDispatcher.storeRelease(eventDispatcher);
|
|
||||||
eventDispatcher->startingUp();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +117,14 @@ void QThreadData::deref()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QAbstractEventDispatcher *QThreadData::createEventDispatcher()
|
||||||
|
{
|
||||||
|
QAbstractEventDispatcher *ed = QThreadPrivate::createEventDispatcher(this);
|
||||||
|
eventDispatcher.storeRelease(ed);
|
||||||
|
ed->startingUp();
|
||||||
|
return ed;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
QAdoptedThread
|
QAdoptedThread
|
||||||
*/
|
*/
|
||||||
|
@ -248,7 +248,15 @@ public:
|
|||||||
void ref();
|
void ref();
|
||||||
void deref();
|
void deref();
|
||||||
inline bool hasEventDispatcher() const
|
inline bool hasEventDispatcher() const
|
||||||
{ return eventDispatcher.load() != 0; }
|
{ return eventDispatcher.load() != nullptr; }
|
||||||
|
QAbstractEventDispatcher *createEventDispatcher();
|
||||||
|
QAbstractEventDispatcher *ensureEventDispatcher()
|
||||||
|
{
|
||||||
|
QAbstractEventDispatcher *ed = eventDispatcher.load();
|
||||||
|
if (Q_LIKELY(ed))
|
||||||
|
return ed;
|
||||||
|
return createEventDispatcher();
|
||||||
|
}
|
||||||
|
|
||||||
bool canWaitLocked()
|
bool canWaitLocked()
|
||||||
{
|
{
|
||||||
|
@ -339,13 +339,7 @@ void *QThreadPrivate::start(void *arg)
|
|||||||
data->quitNow = thr->d_func()->exited;
|
data->quitNow = thr->d_func()->exited;
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractEventDispatcher *eventDispatcher = data->eventDispatcher.load();
|
data->ensureEventDispatcher();
|
||||||
if (!eventDispatcher) {
|
|
||||||
eventDispatcher = createEventDispatcher(data);
|
|
||||||
data->eventDispatcher.storeRelease(eventDispatcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
eventDispatcher->startingUp();
|
|
||||||
|
|
||||||
#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX))
|
#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX))
|
||||||
{
|
{
|
||||||
|
@ -360,13 +360,7 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi
|
|||||||
data->quitNow = thr->d_func()->exited;
|
data->quitNow = thr->d_func()->exited;
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractEventDispatcher *eventDispatcher = data->eventDispatcher.load();
|
data->ensureEventDispatcher();
|
||||||
if (!eventDispatcher) {
|
|
||||||
eventDispatcher = createEventDispatcher(data);
|
|
||||||
data->eventDispatcher.storeRelease(eventDispatcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
eventDispatcher->startingUp();
|
|
||||||
|
|
||||||
#if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINRT)
|
#if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINRT)
|
||||||
// sets the name of the current thread.
|
// sets the name of the current thread.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user