diff options
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 865e16a3f0..2feeae5394 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -120,6 +120,7 @@ #ifdef Q_OS_WASM #include <emscripten.h> +#include <emscripten/val.h> #endif #ifdef QT_BOOTSTRAPPED @@ -216,22 +217,24 @@ QString QCoreApplicationPrivate::appVersion() const } #endif -QString *QCoreApplicationPrivate::cachedApplicationFilePath = 0; +QString *QCoreApplicationPrivate::cachedApplicationFilePath = nullptr; bool QCoreApplicationPrivate::checkInstance(const char *function) { - bool b = (QCoreApplication::self != 0); + bool b = (QCoreApplication::self != nullptr); if (!b) qWarning("QApplication::%s: Please instantiate the QApplication object first", function); return b; } +#if QT_CONFIG(commandlineparser) void QCoreApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options) { options->append(QCommandLineOption(QStringLiteral("qmljsdebugger"), QStringLiteral("Activates the QML/JS debugger with a specified port. The value must be of format port:1234[,block]. \"block\" makes the application wait for a connection."), QStringLiteral("value"))); } +#endif void QCoreApplicationPrivate::processCommandLineArguments() { @@ -257,7 +260,7 @@ void QCoreApplicationPrivate::processCommandLineArguments() } if (j < argc) { - argv[j] = 0; + argv[j] = nullptr; argc = j; } } @@ -367,11 +370,11 @@ Q_CORE_EXPORT uint qGlobalPostedEventsCount() return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset; } -QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = 0; +QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = nullptr; #endif // QT_NO_QOBJECT -QCoreApplication *QCoreApplication::self = 0; +QCoreApplication *QCoreApplication::self = nullptr; uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents) | (1 << Qt::AA_SynthesizeMouseForUnhandledTabletEvents); @@ -384,8 +387,8 @@ struct QCoreApplicationData { ~QCoreApplicationData() { #ifndef QT_NO_QOBJECT // cleanup the QAdoptedThread created for the main() thread - if (QCoreApplicationPrivate::theMainThread) { - QThreadData *data = QThreadData::get2(QCoreApplicationPrivate::theMainThread); + if (auto *t = QCoreApplicationPrivate::theMainThread.loadAcquire()) { + QThreadData *data = QThreadData::get2(t); data->deref(); // deletes the data and the adopted thread } #endif @@ -455,12 +458,12 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint , aboutToQuitEmitted(false) , threadData_clean(false) #else - , q_ptr(0) + , q_ptr(nullptr) #endif { app_compile_version = flags & 0xffffff; static const char *const empty = ""; - if (argc == 0 || argv == 0) { + if (argc == 0 || argv == nullptr) { argc = 0; argv = const_cast<char **>(&empty); } @@ -485,7 +488,7 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint #endif QThread *cur = QThread::currentThread(); // note: this may end up setting theMainThread! - if (cur != theMainThread) + if (cur != theMainThread.loadAcquire()) qWarning("WARNING: QApplication was not created in the main() thread."); #endif } @@ -551,8 +554,8 @@ void QCoreApplicationPrivate::eventDispatcherReady() QBasicAtomicPointer<QThread> QCoreApplicationPrivate::theMainThread = Q_BASIC_ATOMIC_INITIALIZER(0); QThread *QCoreApplicationPrivate::mainThread() { - Q_ASSERT(theMainThread.load() != 0); - return theMainThread.load(); + Q_ASSERT(theMainThread.loadRelaxed() != 0); + return theMainThread.loadRelaxed(); } bool QCoreApplicationPrivate::threadRequiresCoreApplication() @@ -799,6 +802,10 @@ void QCoreApplicationPrivate::init() Module.print(err); }); ); + +#if QT_CONFIG(thread) + QThreadPrivate::idealThreadCount = emscripten::val::global("navigator")["hardwareConcurrency"].as<int>(); +#endif #endif // Store app name/version (so they're still available after QCoreApplication is destroyed) @@ -849,7 +856,7 @@ void QCoreApplicationPrivate::init() #ifndef QT_NO_QOBJECT // use the event dispatcher created by the app programmer (if any) Q_ASSERT(!eventDispatcher); - eventDispatcher = threadData->eventDispatcher.load(); + eventDispatcher = threadData->eventDispatcher.loadRelaxed(); // otherwise we create one if (!eventDispatcher) @@ -857,7 +864,7 @@ void QCoreApplicationPrivate::init() Q_ASSERT(eventDispatcher); if (!eventDispatcher->parent()) { - eventDispatcher->moveToThread(threadData->thread); + eventDispatcher->moveToThread(threadData->thread.loadAcquire()); eventDispatcher->setParent(q); } @@ -886,7 +893,7 @@ QCoreApplication::~QCoreApplication() { qt_call_post_routines(); - self = 0; + self = nullptr; #ifndef QT_NO_QOBJECT QCoreApplicationPrivate::is_app_closing = true; QCoreApplicationPrivate::is_app_running = false; @@ -894,7 +901,7 @@ QCoreApplication::~QCoreApplication() #if QT_CONFIG(thread) // Synchronize and stop the global thread pool threads. - QThreadPool *globalThreadPool = 0; + QThreadPool *globalThreadPool = nullptr; QT_TRY { globalThreadPool = QThreadPool::globalInstance(); } QT_CATCH (...) { @@ -905,10 +912,10 @@ QCoreApplication::~QCoreApplication() #endif #ifndef QT_NO_QOBJECT - d_func()->threadData->eventDispatcher = 0; + d_func()->threadData->eventDispatcher = nullptr; if (QCoreApplicationPrivate::eventDispatcher) QCoreApplicationPrivate::eventDispatcher->closingDown(); - QCoreApplicationPrivate::eventDispatcher = 0; + QCoreApplicationPrivate::eventDispatcher = nullptr; #endif #if QT_CONFIG(library) @@ -972,7 +979,11 @@ void QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, bool on) QCoreApplicationPrivate::attribs |= 1 << attribute; else QCoreApplicationPrivate::attribs &= ~(1 << attribute); +#if defined(QT_NO_QOBJECT) if (Q_UNLIKELY(qApp)) { +#else + if (Q_UNLIKELY(QCoreApplicationPrivate::is_app_running)) { +#endif switch (attribute) { case Qt::AA_EnableHighDpiScaling: case Qt::AA_DisableHighDpiScaling: @@ -1172,7 +1183,7 @@ static bool doNotify(QObject *receiver, QEvent *event) bool QCoreApplicationPrivate::sendThroughApplicationEventFilters(QObject *receiver, QEvent *event) { // We can't access the application event filters outside of the main thread (race conditions) - Q_ASSERT(receiver->d_func()->threadData->thread == mainThread()); + Q_ASSERT(receiver->d_func()->threadData->thread.loadAcquire() == mainThread()); if (extraData) { // application event filters are only called for objects in the GUI thread @@ -1225,7 +1236,7 @@ bool QCoreApplicationPrivate::notify_helper(QObject *receiver, QEvent * event) // send to all application event filters (only does anything in the main thread) if (QCoreApplication::self - && receiver->d_func()->threadData->thread == mainThread() + && receiver->d_func()->threadData->thread.loadAcquire() == mainThread() && QCoreApplication::self->d_func()->sendThroughApplicationEventFilters(receiver, event)) { filtered = true; return filtered; @@ -1297,7 +1308,7 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags) QThreadData *data = QThreadData::current(); if (!data->hasEventDispatcher()) return; - data->eventDispatcher.load()->processEvents(flags); + data->eventDispatcher.loadRelaxed()->processEvents(flags); } /*! @@ -1329,7 +1340,7 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int m return; QElapsedTimer start; start.start(); - while (data->eventDispatcher.load()->processEvents(flags & ~QEventLoop::WaitForMoreEvents)) { + while (data->eventDispatcher.loadRelaxed()->processEvents(flags & ~QEventLoop::WaitForMoreEvents)) { if (start.elapsed() > ms) break; } @@ -1733,7 +1744,7 @@ void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type --data->postEventList.recursion; if (!data->postEventList.recursion && !data->canWait && data->hasEventDispatcher()) - data->eventDispatcher.load()->wakeUp(); + data->eventDispatcher.loadRelaxed()->wakeUp(); // clear the global list, i.e. remove everything that was // delivered. @@ -1984,7 +1995,7 @@ void QCoreApplicationPrivate::deref() void QCoreApplicationPrivate::maybeQuit() { - if (quitLockRef.load() == 0 && in_exec && quitLockRefEnabled && shouldQuit()) + if (quitLockRef.loadRelaxed() == 0 && in_exec && quitLockRefEnabled && shouldQuit()) QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::Quit)); } @@ -2646,7 +2657,7 @@ QString QCoreApplication::applicationVersion() #if QT_CONFIG(library) -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, libraryPathMutex, (QMutex::Recursive)) +Q_GLOBAL_STATIC(QRecursiveMutex, libraryPathMutex) /*! Returns a list of paths that the application will search when @@ -2896,7 +2907,7 @@ void QCoreApplication::installNativeEventFilter(QAbstractNativeEventFilter *filt return; } - QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(QCoreApplicationPrivate::theMainThread); + QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(QCoreApplicationPrivate::theMainThread.loadAcquire()); if (!filterObj || !eventDispatcher) return; eventDispatcher->installNativeEventFilter(filterObj); @@ -2952,8 +2963,8 @@ bool QCoreApplication::hasPendingEvents() */ QAbstractEventDispatcher *QCoreApplication::eventDispatcher() { - if (QCoreApplicationPrivate::theMainThread) - return QCoreApplicationPrivate::theMainThread.load()->eventDispatcher(); + if (QCoreApplicationPrivate::theMainThread.loadAcquire()) + return QCoreApplicationPrivate::theMainThread.loadRelaxed()->eventDispatcher(); return 0; } @@ -2965,7 +2976,7 @@ QAbstractEventDispatcher *QCoreApplication::eventDispatcher() */ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatcher) { - QThread *mainThread = QCoreApplicationPrivate::theMainThread; + QThread *mainThread = QCoreApplicationPrivate::theMainThread.loadAcquire(); if (!mainThread) mainThread = QThread::currentThread(); // will also setup theMainThread mainThread->setEventDispatcher(eventDispatcher); |