Make QThreadPrivate::createEventDispatcher do exactly what it says

Leaving the logic of starting up the event dispatcher to the call site,
unified both the case of a custom event dispatcher and the default
event dispatcher.

The data argument is left in due to the static nature of the function.

Change-Id: Ia2020e39ccc67cd5a583d4e614dd978b2ec44dba
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Tor Arne Vestbø 2018-02-13 14:37:05 +01:00
parent fe5edcee60
commit 54d57cbd6f
4 changed files with 30 additions and 24 deletions

View File

@ -102,7 +102,9 @@ QEventLoop::QEventLoop(QObject *parent)
if (!QCoreApplication::instance() && QCoreApplicationPrivate::threadRequiresCoreApplication()) {
qWarning("QEventLoop: Cannot be used without QApplication");
} else if (!d->threadData->hasEventDispatcher()) {
QThreadPrivate::createEventDispatcher(d->threadData);
QAbstractEventDispatcher *eventDispatcher = QThreadPrivate::createEventDispatcher(d->threadData);
d->threadData->eventDispatcher.storeRelease(eventDispatcher);
eventDispatcher->startingUp();
}
}

View File

@ -195,7 +195,7 @@ public:
#endif // Q_OS_WIN
QThreadData *data;
static void createEventDispatcher(QThreadData *data);
static QAbstractEventDispatcher *createEventDispatcher(QThreadData *data);
void ref()
{
@ -222,7 +222,7 @@ public:
static void setCurrentThread(QThread*) {}
static QThread *threadForId(int) { return QThread::currentThread(); }
static void createEventDispatcher(QThreadData *data);
static QAbstractEventDispatcher *createEventDispatcher(QThreadData *data);
void ref() {}
void deref() {}

View File

@ -285,27 +285,26 @@ typedef void*(*QtThreadCallback)(void*);
#endif // QT_NO_THREAD
void QThreadPrivate::createEventDispatcher(QThreadData *data)
QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *data)
{
Q_UNUSED(data);
#if defined(Q_OS_DARWIN)
bool ok = false;
int value = qEnvironmentVariableIntValue("QT_EVENT_DISPATCHER_CORE_FOUNDATION", &ok);
if (ok && value > 0)
data->eventDispatcher.storeRelease(new QEventDispatcherCoreFoundation);
return new QEventDispatcherCoreFoundation;
else
data->eventDispatcher.storeRelease(new QEventDispatcherUNIX);
return new QEventDispatcherUNIX;
#elif !defined(QT_NO_GLIB)
if (qEnvironmentVariableIsEmpty("QT_NO_GLIB")
&& qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")
&& QEventDispatcherGlib::versionSupported())
data->eventDispatcher.storeRelease(new QEventDispatcherGlib);
return new QEventDispatcherGlib;
else
data->eventDispatcher.storeRelease(new QEventDispatcherUNIX);
return new QEventDispatcherUNIX;
#else
data->eventDispatcher.storeRelease(new QEventDispatcherUNIX);
return new QEventDispatcherUNIX;
#endif
data->eventDispatcher.load()->startingUp();
}
#ifndef QT_NO_THREAD
@ -352,10 +351,13 @@ void *QThreadPrivate::start(void *arg)
data->quitNow = thr->d_func()->exited;
}
if (data->hasEventDispatcher()) // custom event dispatcher set?
data->eventDispatcher.load()->startingUp();
else
createEventDispatcher(data);
QAbstractEventDispatcher *eventDispatcher = data->eventDispatcher.load();
if (!eventDispatcher) {
eventDispatcher = createEventDispatcher(data);
data->eventDispatcher.storeRelease(eventDispatcher);
}
eventDispatcher->startingUp();
#if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX))
{

View File

@ -331,15 +331,14 @@ void qt_set_thread_name(HANDLE threadId, LPCSTR threadName)
#endif // QT_NO_THREAD
void QThreadPrivate::createEventDispatcher(QThreadData *data)
QAbstractEventDispatcher *QThreadPrivate::createEventDispatcher(QThreadData *data)
{
Q_UNUSED(data);
#ifndef Q_OS_WINRT
QEventDispatcherWin32 *theEventDispatcher = new QEventDispatcherWin32;
return new QEventDispatcherWin32;
#else
QEventDispatcherWinRT *theEventDispatcher = new QEventDispatcherWinRT;
return new QEventDispatcherWinRT;
#endif
data->eventDispatcher.storeRelease(theEventDispatcher);
theEventDispatcher->startingUp();
}
#ifndef QT_NO_THREAD
@ -360,10 +359,13 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi
data->quitNow = thr->d_func()->exited;
}
if (data->hasEventDispatcher()) // custom event dispatcher set?
data->eventDispatcher.load()->startingUp();
else
createEventDispatcher(data);
QAbstractEventDispatcher *eventDispatcher = data->eventDispatcher.load();
if (!eventDispatcher) {
eventDispatcher = createEventDispatcher(data);
data->eventDispatcher.storeRelease(eventDispatcher);
}
eventDispatcher->startingUp();
#if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINRT)
// sets the name of the current thread.