forked from qt-creator/qt-creator
Use more Utils::isMainThread()
Change-Id: Ia3c6f6dca53c5d7487b0813de16f06c52af47aa5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/qtcsettings.h>
|
#include <utils/qtcsettings.h>
|
||||||
|
#include <utils/threadutils.h>
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
@@ -851,7 +852,7 @@ bool PluginManager::finishScenario()
|
|||||||
// Waits until the running scenario is fully initialized
|
// Waits until the running scenario is fully initialized
|
||||||
void PluginManager::waitForScenarioFullyInitialized()
|
void PluginManager::waitForScenarioFullyInitialized()
|
||||||
{
|
{
|
||||||
if (QThread::currentThread() == qApp->thread()) {
|
if (isMainThread()) {
|
||||||
qWarning("The waitForScenarioFullyInitialized() function can't be called from main thread.");
|
qWarning("The waitForScenarioFullyInitialized() function can't be called from main thread.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1378,7 +1379,7 @@ void PluginManagerPrivate::shutdown()
|
|||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
if (PluginManager::isScenarioRunning("TestModelManagerInterface")) {
|
if (PluginManager::isScenarioRunning("TestModelManagerInterface")) {
|
||||||
qDebug() << "Point 2: Expect the next call to Point 3 triggers a crash";
|
qDebug() << "Point 2: Expect the next call to Point 3 triggers a crash";
|
||||||
QThread::currentThread()->sleep(5);
|
QThread::sleep(5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!allObjects.isEmpty()) {
|
if (!allObjects.isEmpty()) {
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
#include "qmljsinterpreter.h"
|
#include "qmljsinterpreter.h"
|
||||||
#include "qmljsmodelmanagerinterface.h"
|
#include "qmljsmodelmanagerinterface.h"
|
||||||
#include "qmljsplugindumper.h"
|
#include "qmljsplugindumper.h"
|
||||||
#include "qmljstypedescriptionreader.h"
|
|
||||||
#include "qmljsdialect.h"
|
#include "qmljsdialect.h"
|
||||||
#include "qmljsviewercontext.h"
|
#include "qmljsviewercontext.h"
|
||||||
#include "qmljsutils.h"
|
#include "qmljsutils.h"
|
||||||
@@ -989,7 +988,7 @@ void ModelManagerInterface::parseLoop(QSet<Utils::FilePath> &scannedPaths,
|
|||||||
ExtensionSystem::PluginManager::waitForScenarioFullyInitialized();
|
ExtensionSystem::PluginManager::waitForScenarioFullyInitialized();
|
||||||
if (ExtensionSystem::PluginManager::finishScenario()) {
|
if (ExtensionSystem::PluginManager::finishScenario()) {
|
||||||
qDebug() << "Point 1: Shutdown triggered";
|
qDebug() << "Point 1: Shutdown triggered";
|
||||||
QThread::currentThread()->sleep(2);
|
QThread::sleep(2);
|
||||||
qDebug() << "Point 3: If Point 2 was already reached, expect a crash now";
|
qDebug() << "Point 3: If Point 2 was already reached, expect a crash now";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#include "processreaper.h"
|
#include "processreaper.h"
|
||||||
#include "processutils.h"
|
#include "processutils.h"
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
|
#include "threadutils.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -224,7 +225,7 @@ ProcessReaper::ProcessReaper()
|
|||||||
|
|
||||||
ProcessReaper::~ProcessReaper()
|
ProcessReaper::~ProcessReaper()
|
||||||
{
|
{
|
||||||
QTC_CHECK(QThread::currentThread() == qApp->thread());
|
QTC_CHECK(isMainThread());
|
||||||
QMutexLocker locker(&s_instanceMutex);
|
QMutexLocker locker(&s_instanceMutex);
|
||||||
instance()->m_private->waitForFinished();
|
instance()->m_private->waitForFinished();
|
||||||
m_thread.quit();
|
m_thread.quit();
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#include "processreaper.h"
|
#include "processreaper.h"
|
||||||
#include "processutils.h"
|
#include "processutils.h"
|
||||||
#include "terminalprocess_p.h"
|
#include "terminalprocess_p.h"
|
||||||
|
#include "threadutils.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -62,25 +63,25 @@ public:
|
|||||||
timer.start();
|
timer.start();
|
||||||
auto cleanup = qScopeGuard([this, &timer] {
|
auto cleanup = qScopeGuard([this, &timer] {
|
||||||
const qint64 currentNsecs = timer.nsecsElapsed();
|
const qint64 currentNsecs = timer.nsecsElapsed();
|
||||||
const bool isMainThread = QThread::currentThread() == qApp->thread();
|
const bool mainThread = isMainThread();
|
||||||
const int hitThisAll = m_hitThisAll.fetch_add(1) + 1;
|
const int hitThisAll = m_hitThisAll.fetch_add(1) + 1;
|
||||||
const int hitAllAll = m_hitAllAll.fetch_add(1) + 1;
|
const int hitAllAll = m_hitAllAll.fetch_add(1) + 1;
|
||||||
const int hitThisMain = isMainThread
|
const int hitThisMain = mainThread
|
||||||
? m_hitThisMain.fetch_add(1) + 1
|
? m_hitThisMain.fetch_add(1) + 1
|
||||||
: m_hitThisMain.load();
|
: m_hitThisMain.load();
|
||||||
const int hitAllMain = isMainThread
|
const int hitAllMain = mainThread
|
||||||
? m_hitAllMain.fetch_add(1) + 1
|
? m_hitAllMain.fetch_add(1) + 1
|
||||||
: m_hitAllMain.load();
|
: m_hitAllMain.load();
|
||||||
const qint64 totalThisAll = toMs(m_totalThisAll.fetch_add(currentNsecs) + currentNsecs);
|
const qint64 totalThisAll = toMs(m_totalThisAll.fetch_add(currentNsecs) + currentNsecs);
|
||||||
const qint64 totalAllAll = toMs(m_totalAllAll.fetch_add(currentNsecs) + currentNsecs);
|
const qint64 totalAllAll = toMs(m_totalAllAll.fetch_add(currentNsecs) + currentNsecs);
|
||||||
const qint64 totalThisMain = toMs(isMainThread
|
const qint64 totalThisMain = toMs(mainThread
|
||||||
? m_totalThisMain.fetch_add(currentNsecs) + currentNsecs
|
? m_totalThisMain.fetch_add(currentNsecs) + currentNsecs
|
||||||
: m_totalThisMain.load());
|
: m_totalThisMain.load());
|
||||||
const qint64 totalAllMain = toMs(isMainThread
|
const qint64 totalAllMain = toMs(mainThread
|
||||||
? m_totalAllMain.fetch_add(currentNsecs) + currentNsecs
|
? m_totalAllMain.fetch_add(currentNsecs) + currentNsecs
|
||||||
: m_totalAllMain.load());
|
: m_totalAllMain.load());
|
||||||
printMeasurement(QLatin1String(m_functionName), hitThisAll, toMs(currentNsecs),
|
printMeasurement(QLatin1String(m_functionName), hitThisAll, toMs(currentNsecs),
|
||||||
totalThisAll, hitAllAll, totalAllAll, isMainThread,
|
totalThisAll, hitAllAll, totalAllAll, mainThread,
|
||||||
hitThisMain, totalThisMain, hitAllMain, totalAllMain);
|
hitThisMain, totalThisMain, hitAllMain, totalAllMain);
|
||||||
});
|
});
|
||||||
return std::invoke(std::forward<Function>(function), std::forward<Args>(args)...);
|
return std::invoke(std::forward<Function>(function), std::forward<Args>(args)...);
|
||||||
@@ -1212,7 +1213,7 @@ void QtcProcess::setRemoteProcessHooks(const DeviceProcessHooks &hooks)
|
|||||||
static bool askToKill(const QString &command)
|
static bool askToKill(const QString &command)
|
||||||
{
|
{
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
if (QThread::currentThread() != QCoreApplication::instance()->thread())
|
if (!isMainThread())
|
||||||
return true;
|
return true;
|
||||||
const QString title = QtcProcess::tr("Process Not Responding");
|
const QString title = QtcProcess::tr("Process Not Responding");
|
||||||
QString msg = command.isEmpty() ?
|
QString msg = command.isEmpty() ?
|
||||||
@@ -1775,13 +1776,6 @@ void QtcProcess::setWriteData(const QByteArray &writeData)
|
|||||||
d->m_setup.m_writeData = writeData;
|
d->m_setup.m_writeData = writeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef QT_GUI_LIB
|
|
||||||
static bool isGuiThread()
|
|
||||||
{
|
|
||||||
return QThread::currentThread() == QCoreApplication::instance()->thread();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void QtcProcess::runBlocking(EventLoopMode eventLoopMode)
|
void QtcProcess::runBlocking(EventLoopMode eventLoopMode)
|
||||||
{
|
{
|
||||||
// Attach a dynamic property with info about blocking type
|
// Attach a dynamic property with info about blocking type
|
||||||
@@ -1802,7 +1796,7 @@ void QtcProcess::runBlocking(EventLoopMode eventLoopMode)
|
|||||||
timer.setInterval(1000);
|
timer.setInterval(1000);
|
||||||
timer.start();
|
timer.start();
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
if (isGuiThread())
|
if (isMainThread())
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
#endif
|
#endif
|
||||||
QEventLoop eventLoop(this);
|
QEventLoop eventLoop(this);
|
||||||
@@ -1812,7 +1806,7 @@ void QtcProcess::runBlocking(EventLoopMode eventLoopMode)
|
|||||||
d->m_eventLoop = nullptr;
|
d->m_eventLoop = nullptr;
|
||||||
timer.stop();
|
timer.stop();
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
if (isGuiThread())
|
if (isMainThread())
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -3,10 +3,9 @@
|
|||||||
|
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
#include "singleton.h"
|
#include "singleton.h"
|
||||||
|
#include "threadutils.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ SingletonStaticData &Singleton::staticData(std::type_index index)
|
|||||||
// only.
|
// only.
|
||||||
void Singleton::deleteAll()
|
void Singleton::deleteAll()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(QThread::currentThread() == qApp->thread(), return);
|
QTC_ASSERT(isMainThread(), return);
|
||||||
QList<Singleton *> oldList;
|
QList<Singleton *> oldList;
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
|
@@ -119,7 +119,7 @@ void StringTablePrivate::GC(QFutureInterface<void> &futureInterface)
|
|||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
if (ExtensionSystem::PluginManager::isScenarioRunning("TestStringTable")) {
|
if (ExtensionSystem::PluginManager::isScenarioRunning("TestStringTable")) {
|
||||||
if (ExtensionSystem::PluginManager::finishScenario())
|
if (ExtensionSystem::PluginManager::finishScenario())
|
||||||
QThread::currentThread()->sleep(5);
|
QThread::sleep(5);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -3,11 +3,9 @@
|
|||||||
|
|
||||||
#include "projectnodes.h"
|
#include "projectnodes.h"
|
||||||
|
|
||||||
#include "buildconfiguration.h"
|
|
||||||
#include "buildsystem.h"
|
#include "buildsystem.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "projectexplorerconstants.h"
|
#include "projectexplorerconstants.h"
|
||||||
#include "projecttree.h"
|
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -21,14 +19,12 @@
|
|||||||
#include <utils/pointeralgorithm.h>
|
#include <utils/pointeralgorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
|
#include <utils/threadutils.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QStyle>
|
|
||||||
#include <QThread>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -445,7 +441,7 @@ QString FolderNode::displayName() const
|
|||||||
*/
|
*/
|
||||||
QIcon FolderNode::icon() const
|
QIcon FolderNode::icon() const
|
||||||
{
|
{
|
||||||
QTC_CHECK(QThread::currentThread() == QCoreApplication::instance()->thread());
|
QTC_CHECK(isMainThread());
|
||||||
|
|
||||||
// Instantiating the Icon provider is expensive.
|
// Instantiating the Icon provider is expensive.
|
||||||
if (auto strPtr = std::get_if<QString>(&m_icon)) {
|
if (auto strPtr = std::get_if<QString>(&m_icon)) {
|
||||||
@@ -1063,7 +1059,7 @@ DirectoryIcon::DirectoryIcon(const QString &overlay)
|
|||||||
*/
|
*/
|
||||||
QIcon DirectoryIcon::icon() const
|
QIcon DirectoryIcon::icon() const
|
||||||
{
|
{
|
||||||
QTC_CHECK(QThread::currentThread() == QCoreApplication::instance()->thread());
|
QTC_CHECK(isMainThread());
|
||||||
const auto it = m_cache.find(m_overlay);
|
const auto it = m_cache.find(m_overlay);
|
||||||
if (it != m_cache.end())
|
if (it != m_cache.end())
|
||||||
return it.value();
|
return it.value();
|
||||||
|
@@ -9,10 +9,10 @@
|
|||||||
#include <texteditor/textmark.h>
|
#include <texteditor/textmark.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
#include <utils/threadutils.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ void TaskHub::addTask(Task::TaskType type, const QString &description, Utils::Id
|
|||||||
|
|
||||||
void TaskHub::addTask(Task task)
|
void TaskHub::addTask(Task task)
|
||||||
{
|
{
|
||||||
if (QThread::currentThread() != qApp->thread()) {
|
if (!isMainThread()) {
|
||||||
QMetaObject::invokeMethod(qApp, [task = std::move(task)] {
|
QMetaObject::invokeMethod(qApp, [task = std::move(task)] {
|
||||||
TaskHub::addTask(task);
|
TaskHub::addTask(task);
|
||||||
});
|
});
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/threadutils.h>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <qt_windows.h>
|
#include <qt_windows.h>
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ void WinDebugInterface::emitReadySignal()
|
|||||||
void WinDebugInterface::dispatchDebugOutput()
|
void WinDebugInterface::dispatchDebugOutput()
|
||||||
{
|
{
|
||||||
// Called in the thread this object was created in, not in the WinDebugInterfaceThread.
|
// Called in the thread this object was created in, not in the WinDebugInterfaceThread.
|
||||||
QTC_ASSERT(QThread::currentThread() == QCoreApplication::instance()->thread(), return);
|
QTC_ASSERT(Utils::isMainThread(), return);
|
||||||
|
|
||||||
static size_t maxMessagesToSend = 100;
|
static size_t maxMessagesToSend = 100;
|
||||||
std::vector<std::pair<qint64, QString>> output;
|
std::vector<std::pair<qint64, QString>> output;
|
||||||
|
@@ -29,7 +29,6 @@
|
|||||||
#include "nodeabstractproperty.h"
|
#include "nodeabstractproperty.h"
|
||||||
#include "nodeinstanceserverproxy.h"
|
#include "nodeinstanceserverproxy.h"
|
||||||
#include "nodelistproperty.h"
|
#include "nodelistproperty.h"
|
||||||
#include "nodeproperty.h"
|
|
||||||
#include "pixmapchangedcommand.h"
|
#include "pixmapchangedcommand.h"
|
||||||
#include "puppettocreatorcommand.h"
|
#include "puppettocreatorcommand.h"
|
||||||
#include "qml3dnode.h"
|
#include "qml3dnode.h"
|
||||||
@@ -84,19 +83,18 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
#include <utils/threadutils.h>
|
||||||
|
|
||||||
#include <qtsupport/qtkitinformation.h>
|
#include <qtsupport/qtkitinformation.h>
|
||||||
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QMultiHash>
|
|
||||||
#include <QTimerEvent>
|
|
||||||
#include <QPicture>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
|
#include <QMultiHash>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPicture>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QThread>
|
#include <QTimerEvent>
|
||||||
#include <QApplication>
|
#include <QUrl>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
debug = false
|
debug = false
|
||||||
@@ -261,7 +259,7 @@ void NodeInstanceView::modelAttached(Model *model)
|
|||||||
// If model gets attached on non-main thread of the application, do not attempt to monitor
|
// If model gets attached on non-main thread of the application, do not attempt to monitor
|
||||||
// file changes. Such models are typically short lived for specific purpose, and timers
|
// file changes. Such models are typically short lived for specific purpose, and timers
|
||||||
// will not work at all, if the thread is not based on QThread.
|
// will not work at all, if the thread is not based on QThread.
|
||||||
if (QThread::currentThread() == qApp->thread()) {
|
if (Utils::isMainThread()) {
|
||||||
m_generateQsbFilesTimer.stop();
|
m_generateQsbFilesTimer.stop();
|
||||||
m_qsbTargets.clear();
|
m_qsbTargets.clear();
|
||||||
updateQsbPathToFilterMap();
|
updateQsbPathToFilterMap();
|
||||||
|
@@ -28,10 +28,8 @@
|
|||||||
#include <utils/parameteraction.h>
|
#include <utils/parameteraction.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/threadutils.h>
|
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
|
@@ -21,6 +21,8 @@ add_qtc_executable(qtcreator_processlauncher
|
|||||||
${UTILSDIR}/qtcassert.h
|
${UTILSDIR}/qtcassert.h
|
||||||
${UTILSDIR}/singleton.cpp
|
${UTILSDIR}/singleton.cpp
|
||||||
${UTILSDIR}/singleton.h
|
${UTILSDIR}/singleton.h
|
||||||
|
${UTILSDIR}/threadutils.cpp
|
||||||
|
${UTILSDIR}/threadutils.h
|
||||||
)
|
)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
@@ -40,6 +40,8 @@ QtcTool {
|
|||||||
"qtcassert.h",
|
"qtcassert.h",
|
||||||
"singleton.cpp",
|
"singleton.cpp",
|
||||||
"singleton.h",
|
"singleton.h",
|
||||||
|
"threadutils.cpp",
|
||||||
|
"threadutils.h",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user