diff options
Diffstat (limited to 'src/gui/kernel/qguiapplication.cpp')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 2a5a4933907..1e44ac83361 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -99,6 +99,10 @@ #include <private/qvulkandefaultinstance_p.h> #endif +#if QT_CONFIG(thread) +#include <QtCore/QThreadPool> +#endif + #include <qtgui_tracepoints_p.h> #include <private/qtools_p.h> @@ -686,6 +690,20 @@ QGuiApplication::~QGuiApplication() d->cursor_list.clear(); #endif +#if QT_CONFIG(qtgui_threadpool) + // Synchronize and stop the gui thread pool threads. + QThreadPool *guiThreadPool = nullptr; + QT_TRY { + guiThreadPool = QGuiApplicationPrivate::qtGuiThreadPool(); + } QT_CATCH (...) { + // swallow the exception, since destructors shouldn't throw + } + if (guiThreadPool) { + guiThreadPool->waitForDone(); + delete guiThreadPool; + } +#endif + delete QGuiApplicationPrivate::app_icon; QGuiApplicationPrivate::app_icon = nullptr; delete QGuiApplicationPrivate::platform_name; @@ -4553,6 +4571,32 @@ QInputDeviceManager *QGuiApplicationPrivate::inputDeviceManager() } /*! + Returns the QThreadPool instance for Qt Gui. + \internal +*/ +QThreadPool *QGuiApplicationPrivate::qtGuiThreadPool() +{ +#if QT_CONFIG(qtgui_threadpool) + Q_CONSTINIT static QPointer<QThreadPool> guiInstance; + Q_CONSTINIT static QBasicMutex theMutex; + const static bool runtime_disable = qEnvironmentVariableIsSet("QT_NO_GUI_THREADPOOL"); + if (runtime_disable) + return nullptr; + const QMutexLocker locker(&theMutex); + if (guiInstance.isNull() && !QCoreApplication::closingDown()) { + guiInstance = new QThreadPool(); + // Limit max thread to avoid too many parallel threads. + // We are not optimized for much more than 4 or 8 threads. + if (guiInstance && guiInstance->maxThreadCount() > 4) + guiInstance->setMaxThreadCount(qBound(4, guiInstance->maxThreadCount() / 2, 8)); + } + return guiInstance; +#else + return nullptr; +#endif +} + +/*! \fn template <typename QNativeInterface> QNativeInterface *QGuiApplication::nativeInterface() const Returns a native interface of the given type for the application. |