QCoreApplication: replace threadRequiresCoreApplication()
With a direct access to the threadData's variable. Amends commit 10c529b08de7cd55b4c3e3654464119246498273 ("Add a way for auxiliary threads to handle events without CoreApp", Qt 5.6), which introduced QDaemonThread, for QtDBus use. We don't need to get the QThreadData from TLS, because we are processing events for an object associated with that particular thread. This removes the only use of QThreadData::current(false) in all of Qt. Refactoring in the next commit(s). Change-Id: Ica2bab556bd431519a1bfffd859911ea7daf062f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
parent
49182a0d57
commit
32ee5539fd
@ -536,14 +536,6 @@ QThread *QCoreApplicationPrivate::mainThread()
|
|||||||
return theMainThread.loadRelaxed();
|
return theMainThread.loadRelaxed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QCoreApplicationPrivate::threadRequiresCoreApplication()
|
|
||||||
{
|
|
||||||
QThreadData *data = QThreadData::current(false);
|
|
||||||
if (!data)
|
|
||||||
return true; // default setting
|
|
||||||
return data->requiresCoreApplication;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver)
|
void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver)
|
||||||
{
|
{
|
||||||
QThread *currentThread = QThread::currentThread();
|
QThread *currentThread = QThread::currentThread();
|
||||||
@ -1107,7 +1099,13 @@ void QCoreApplication::setQuitLockEnabled(bool enabled)
|
|||||||
*/
|
*/
|
||||||
bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event)
|
bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event)
|
||||||
{
|
{
|
||||||
bool selfRequired = QCoreApplicationPrivate::threadRequiresCoreApplication();
|
// Qt enforces the rule that events can only be sent to objects in
|
||||||
|
// the current thread, so receiver->d_func()->threadData is
|
||||||
|
// equivalent to QThreadData::current(), just without the function
|
||||||
|
// call overhead.
|
||||||
|
QObjectPrivate *d = receiver->d_func();
|
||||||
|
QThreadData *threadData = d->threadData.loadAcquire();
|
||||||
|
bool selfRequired = threadData->requiresCoreApplication;
|
||||||
if (selfRequired && !qApp)
|
if (selfRequired && !qApp)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1119,12 +1117,6 @@ bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Qt enforces the rule that events can only be sent to objects in
|
|
||||||
// the current thread, so receiver->d_func()->threadData is
|
|
||||||
// equivalent to QThreadData::current(), just without the function
|
|
||||||
// call overhead.
|
|
||||||
QObjectPrivate *d = receiver->d_func();
|
|
||||||
QThreadData *threadData = d->threadData.loadAcquire();
|
|
||||||
QScopedScopeLevelCounter scopeLevelCounter(threadData);
|
QScopedScopeLevelCounter scopeLevelCounter(threadData);
|
||||||
if (!selfRequired)
|
if (!selfRequired)
|
||||||
return doNotify(receiver, event);
|
return doNotify(receiver, event);
|
||||||
|
@ -113,7 +113,6 @@ public:
|
|||||||
static QBasicAtomicPointer<QThread> theMainThread;
|
static QBasicAtomicPointer<QThread> theMainThread;
|
||||||
static QBasicAtomicPointer<void> theMainThreadId;
|
static QBasicAtomicPointer<void> theMainThreadId;
|
||||||
static QThread *mainThread();
|
static QThread *mainThread();
|
||||||
static bool threadRequiresCoreApplication();
|
|
||||||
|
|
||||||
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data);
|
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data);
|
||||||
|
|
||||||
|
@ -67,10 +67,11 @@ QEventLoop::QEventLoop(QObject *parent)
|
|||||||
: QObject(*new QEventLoopPrivate, parent)
|
: QObject(*new QEventLoopPrivate, parent)
|
||||||
{
|
{
|
||||||
Q_D(QEventLoop);
|
Q_D(QEventLoop);
|
||||||
if (!QCoreApplication::instance() && QCoreApplicationPrivate::threadRequiresCoreApplication()) {
|
QThreadData *threadData = d->threadData.loadRelaxed();
|
||||||
qWarning("QEventLoop: Cannot be used without QApplication");
|
if (!QCoreApplication::instance() && threadData->requiresCoreApplication) {
|
||||||
|
qWarning("QEventLoop: Cannot be used without QCoreApplication");
|
||||||
} else {
|
} else {
|
||||||
d->threadData.loadRelaxed()->ensureEventDispatcher();
|
threadData->ensureEventDispatcher();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3262,8 +3262,9 @@ bool QApplicationPrivate::notify_helper(QObject *receiver, QEvent * e)
|
|||||||
Q_TRACE_EXIT(QApplication_notify_exit, consumed, filtered);
|
Q_TRACE_EXIT(QApplication_notify_exit, consumed, filtered);
|
||||||
|
|
||||||
// send to all application event filters
|
// send to all application event filters
|
||||||
if (threadRequiresCoreApplication()
|
QThreadData *threadData = receiver->d_func()->threadData.loadRelaxed();
|
||||||
&& receiver->d_func()->threadData.loadRelaxed()->thread.loadAcquire() == mainThread()
|
if (threadData->requiresCoreApplication
|
||||||
|
&& threadData->thread.loadAcquire() == mainThread()
|
||||||
&& sendThroughApplicationEventFilters(receiver, e)) {
|
&& sendThroughApplicationEventFilters(receiver, e)) {
|
||||||
filtered = true;
|
filtered = true;
|
||||||
return filtered;
|
return filtered;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user