forked from qt-creator/qt-creator
Clang: Disable internal threads in libclang
We already run all operations in threads to avoid blocking, there is no need to start more threads within libclang. Before this change, a reparse would trigger 3 threads to start: 1. clangbackend: Utils::runAsync() for the job 2. libclang-internal: thread for reparse 3. libclang-internal: thread for annotating tokens (highlighting) Ensure that we use the same stack size for our threads as libclang was doing internally. C++ parsers usually have higher stack size requirements. Change-Id: I2f67602ddfbf77ea2c69144b56acf64ba08041f6 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "clangcodemodelconnectionclient.h"
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -50,6 +51,10 @@ ClangCodeModelConnectionClient::ClangCodeModelConnectionClient(
|
||||
m_processCreator.setTemporaryDirectoryPattern("clangbackend-XXXXXX");
|
||||
m_processCreator.setArguments({connectionName()});
|
||||
|
||||
Utils::Environment environment;
|
||||
environment.set(QStringLiteral("LIBCLANG_NOTHREADS"), QString());
|
||||
m_processCreator.setEnvironment(environment);
|
||||
|
||||
stdErrPrefixer().setPrefix("clangbackend.stderr: ");
|
||||
stdOutPrefixer().setPrefix("clangbackend.stdout: ");
|
||||
}
|
||||
|
||||
@@ -56,6 +56,11 @@ void ProcessCreator::setArguments(const QStringList &arguments)
|
||||
m_arguments = arguments;
|
||||
}
|
||||
|
||||
void ProcessCreator::setEnvironment(const Utils::Environment &environment)
|
||||
{
|
||||
m_environment = environment;
|
||||
}
|
||||
|
||||
std::future<QProcessUniquePointer> ProcessCreator::createProcess() const
|
||||
{
|
||||
return std::async(std::launch::async, [&] {
|
||||
@@ -167,6 +172,10 @@ QProcessEnvironment ProcessCreator::processEnvironment() const
|
||||
processEnvironment.insert("TEMP", temporaryDirectoryPath);
|
||||
}
|
||||
|
||||
const Utils::Environment &env = m_environment;
|
||||
for (auto it = env.constBegin(); it != env.constEnd(); ++it)
|
||||
processEnvironment.insert(it.key(), it.value());
|
||||
|
||||
return processEnvironment;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "processhandle.h"
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
#include <QStringList>
|
||||
@@ -51,6 +52,7 @@ public:
|
||||
void setTemporaryDirectoryPattern(const QString &temporaryDirectoryPattern);
|
||||
void setProcessPath(const QString &m_processPath);
|
||||
void setArguments(const QStringList &m_arguments);
|
||||
void setEnvironment(const Utils::Environment &environment);
|
||||
void setObserver(QObject *m_observer);
|
||||
|
||||
std::future<QProcessUniquePointer> createProcess() const;
|
||||
@@ -72,6 +74,7 @@ private:
|
||||
QString m_processPath;
|
||||
QString m_temporaryDirectoryPattern;
|
||||
QStringList m_arguments;
|
||||
Utils::Environment m_environment;
|
||||
QObject *m_observer = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -58,7 +58,9 @@ public:
|
||||
&QFutureWatcher<Result>::finished,
|
||||
onFinished);
|
||||
|
||||
const QFuture<Result> future = Utils::runAsync(m_runner);
|
||||
// Use 16MB stack size as clang_annotateTokens() would with an internal thread.
|
||||
const Utils::StackSizeInBytes stackSize = 1024 * 1024 * 16;
|
||||
const QFuture<Result> future = Utils::runAsync(stackSize, m_runner);
|
||||
m_futureWatcher.setFuture(future);
|
||||
|
||||
return future;
|
||||
|
||||
Reference in New Issue
Block a user