logic: reduced waiting time when interrupting indexer processes

* made multiprocess AST traversal interruptible again
* removed const variables that define sleep times for threads
This commit is contained in:
mlangkabel
2018-09-21 17:19:03 +02:00
parent 593e075399
commit 951256c07b
44 changed files with 244 additions and 187 deletions
@@ -97,6 +97,8 @@ public class JavaIndexer
visitor = new ContextAwareAstVisitor(astVisitorClient, path.toFile(), fileContent, cu);
}
astVisitorClient.logInfo("starting AST traversal");
cu.accept(visitor);
for (IProblem problem: cu.getProblems())
+1 -2
View File
@@ -172,6 +172,7 @@ add_files(
data/indexer/IndexerCommandType.h
data/indexer/IndexerComposite.cpp
data/indexer/IndexerComposite.h
data/indexer/IndexerStateInfo.h
data/indexer/MemoryIndexerCommandProvider.cpp
data/indexer/MemoryIndexerCommandProvider.h
data/indexer/TaskBuildIndex.cpp
@@ -510,8 +511,6 @@ add_files(
utility/messaging/MessageBase.cpp
utility/messaging/MessageBase.h
utility/messaging/MessageFilter.h
utility/messaging/MessageInterruptTasksCounter.cpp
utility/messaging/MessageInterruptTasksCounter.h
utility/messaging/MessageListener.h
utility/messaging/MessageListenerBase.cpp
utility/messaging/MessageListenerBase.h
+1 -2
View File
@@ -35,8 +35,7 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr<Blackboard> blackboa
}
else
{
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
return STATE_FAILURE;
+1 -2
View File
@@ -42,8 +42,7 @@ Task::TaskState TaskMergeStorages::doUpdate(std::shared_ptr<Blackboard> blackboa
}
else
{
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
return STATE_FAILURE;
+2 -1
View File
@@ -13,12 +13,13 @@ class Indexer
{
public:
IndexerCommandType getSupportedIndexerCommandType() const override;
std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand) override;
private:
virtual std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<T> indexerCommand) = 0;
};
template <typename T>
IndexerCommandType Indexer<T>::getSupportedIndexerCommandType() const
{
-11
View File
@@ -1,16 +1,5 @@
#include "IndexerBase.h"
IndexerBase::IndexerBase()
: m_interrupted(false)
{
}
void IndexerBase::interrupt()
{
m_interrupted = true;
}
bool IndexerBase::interrupted() const
{
return m_interrupted;
}
+1 -9
View File
@@ -15,17 +15,9 @@ class IndexerBase
public:
IndexerBase();
virtual ~IndexerBase() = default;
virtual IndexerCommandType getSupportedIndexerCommandType() const = 0;
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand) = 0;
virtual void interrupt();
bool interrupted() const;
private:
bool m_interrupted;
virtual void interrupt() = 0;
};
#endif // INDEXER_BASE_H
@@ -36,5 +36,4 @@ void IndexerComposite::interrupt()
{
it.second->interrupt();
}
IndexerBase::interrupt();
}
+3 -3
View File
@@ -11,13 +11,13 @@ class IndexerComposite: public IndexerBase
public:
virtual ~IndexerComposite();
virtual IndexerCommandType getSupportedIndexerCommandType() const;
IndexerCommandType getSupportedIndexerCommandType() const override;
void addIndexer(std::shared_ptr<IndexerBase> indexer);
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand);
std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand) override;
virtual void interrupt();
void interrupt() override;
private:
std::map<IndexerCommandType, std::shared_ptr<IndexerBase>> m_indexers;
+10
View File
@@ -0,0 +1,10 @@
#ifndef INDEXER_STATE_INFO_H
#define INDEXER_STATE_INFO_H
struct IndexerStateInfo
{
public:
bool indexingInterrupted;
};
#endif // INDEXER_STATE_INFO_H
+6 -4
View File
@@ -41,6 +41,8 @@ TaskBuildIndex::TaskBuildIndex(
void TaskBuildIndex::doEnter(std::shared_ptr<Blackboard> blackboard)
{
m_interprocessIndexingStatusManager.setIndexingInterrupted(false);
m_indexingFileCount = 0;
updateIndexingDialog(blackboard, std::vector<FilePath>());
@@ -104,8 +106,7 @@ Task::TaskState TaskBuildIndex::doUpdate(std::shared_ptr<Blackboard> blackboard)
updateIndexingDialog(blackboard, std::vector<FilePath>());
}
const int SLEEP_TIME_MS = 50;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
return STATE_RUNNING;
}
@@ -154,6 +155,8 @@ void TaskBuildIndex::handleMessage(MessageInterruptTasks* message)
{
if (!m_dialogView->dialogsHidden())
{
LOG_INFO("sending indexer interrupt command.");
m_interprocessIndexingStatusManager.setIndexingInterrupted(true);
m_interrupted = true;
}
}
@@ -232,8 +235,7 @@ bool TaskBuildIndex::fetchIntermediateStorages(std::shared_ptr<Blackboard> black
{
LOG_INFO_STREAM(<< "waiting, too many storages queued: " << providerStorageCount);
const int SLEEP_TIME_MS = 100;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return true;
}
@@ -82,8 +82,7 @@ Task::TaskState TaskFillIndexerCommandsQueue::doUpdate(std::shared_ptr<Blackboar
}
}
const int SLEEP_TIME_MS = 200;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(200));
return STATE_RUNNING;
}
@@ -5,6 +5,7 @@
#include "FileRegister.h"
#include "logging.h"
#include "LanguagePackageManager.h"
#include "ScopedFunctor.h"
InterprocessIndexer::InterprocessIndexer(const std::string& uuid, Id processId)
: m_interprocessIndexerCommandManager(uuid, processId, false)
@@ -17,10 +18,42 @@ InterprocessIndexer::InterprocessIndexer(const std::string& uuid, Id processId)
void InterprocessIndexer::work()
{
bool updaterThreadRunning = false;
std::shared_ptr<std::thread> updaterThread;
std::shared_ptr<IndexerBase> indexer;
try
{
LOG_INFO(std::to_wstring(m_processId) + L" starting up indexer");
std::shared_ptr<IndexerBase> indexer = LanguagePackageManager::getInstance()->instantiateSupportedIndexers();
indexer = LanguagePackageManager::getInstance()->instantiateSupportedIndexers();
updaterThread = std::make_shared<std::thread>([&]()
{
updaterThreadRunning = true;
while (updaterThreadRunning)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
if (m_interprocessIndexingStatusManager.getIndexingInterrupted())
{
LOG_INFO("received indexer interrupt command.");
if (indexer)
{
indexer->interrupt();
}
updaterThreadRunning = false;
}
}
});
ScopedFunctor threadStopper([&]()
{
updaterThreadRunning = false;
if (updaterThread)
{
updaterThread->join();
updaterThread.reset();
}
});
while (std::shared_ptr<IndexerCommand> indexerCommand = m_interprocessIndexerCommandManager.popIndexerCommand())
{
@@ -29,7 +62,7 @@ void InterprocessIndexer::work()
while (true)
{
size_t storageCount = m_interprocessIntermediateStorageManager.getIntermediateStorageCount();
const size_t storageCount = m_interprocessIntermediateStorageManager.getIntermediateStorageCount();
if (storageCount < 10)
{
break;
@@ -37,8 +70,7 @@ void InterprocessIndexer::work()
LOG_INFO_STREAM(<< m_processId << " waits, too many intermediate storages: " << storageCount);
const int SLEEP_TIME_MS = 200;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
LOG_INFO_STREAM(<< m_processId << " updating indexer status with currently indexed filepath");
@@ -47,8 +79,11 @@ void InterprocessIndexer::work()
LOG_INFO_STREAM(<< m_processId << " starting to index current file");
std::shared_ptr<IntermediateStorage> result = indexer->index(indexerCommand);
LOG_INFO_STREAM(<< m_processId << " pushing index to shared memory");
m_interprocessIntermediateStorageManager.pushIntermediateStorage(result);
if (result)
{
LOG_INFO_STREAM(<< m_processId << " pushing index to shared memory");
m_interprocessIntermediateStorageManager.pushIntermediateStorage(result);
}
LOG_INFO_STREAM(<< m_processId << " finalizing indexer status for current file");
m_interprocessIndexingStatusManager.finishIndexingSourceFile();
@@ -9,6 +9,7 @@ const char* InterprocessIndexingStatusManager::s_indexingFilesKeyName = "indexin
const char* InterprocessIndexingStatusManager::s_currentFilesKeyName = "current_files";
const char* InterprocessIndexingStatusManager::s_crashedFilesKeyName = "crashed_files";
const char* InterprocessIndexingStatusManager::s_finishedProcessIdsKeyName = "finished_process_ids";
const char* InterprocessIndexingStatusManager::s_indexingInterruptedKeyName = "indexing_interrupted_flag";
InterprocessIndexingStatusManager::InterprocessIndexingStatusManager(const std::string& instanceUuid, Id processId, bool isOwner)
: BaseInterprocessDataManager(s_sharedMemoryNamePrefix + instanceUuid, 1048576 /* 1 MB */, instanceUuid, processId, isOwner)
@@ -97,6 +98,32 @@ void InterprocessIndexingStatusManager::finishIndexingSourceFile()
}
}
void InterprocessIndexingStatusManager::setIndexingInterrupted(bool interrupted)
{
SharedMemory::ScopedAccess access(&m_sharedMemory);
bool* indexingInterruptedPtr =
access.accessValue<bool>(s_indexingInterruptedKeyName);
if (indexingInterruptedPtr)
{
*indexingInterruptedPtr = interrupted;
}
}
bool InterprocessIndexingStatusManager::getIndexingInterrupted()
{
SharedMemory::ScopedAccess access(&m_sharedMemory);
bool* indexingInterruptedPtr =
access.accessValue<bool>(s_indexingInterruptedKeyName);
if (indexingInterruptedPtr)
{
return *indexingInterruptedPtr;
}
return false;
}
Id InterprocessIndexingStatusManager::getNextFinishedProcessId()
{
SharedMemory::ScopedAccess access(&m_sharedMemory);
@@ -16,6 +16,9 @@ public:
void startIndexingSourceFile(const FilePath& filePath);
void finishIndexingSourceFile();
void setIndexingInterrupted(bool interrupted);
bool getIndexingInterrupted();
Id getNextFinishedProcessId();
std::vector<FilePath> getCurrentlyIndexedSourceFilePaths();
@@ -28,6 +31,7 @@ private:
static const char* s_currentFilesKeyName;
static const char* s_crashedFilesKeyName;
static const char* s_finishedProcessIdsKeyName;
static const char* s_indexingInterruptedKeyName;
};
#endif // INTERPROCESS_INDEXING_STATUS_MANAGER_H
@@ -116,5 +116,4 @@ private:
AccessMode m_mode;
};
#endif // SHARED_MEMORY_H
@@ -1,40 +0,0 @@
#include "MessageInterruptTasksCounter.h"
#include "MessageInterruptTasks.h"
#include "MessageListener.h"
MessageInterruptTasksCounter::MessageInterruptTasksCounter()
: m_count(0)
{
class InterruptListener: public MessageListener<MessageInterruptTasks>
{
public:
InterruptListener(size_t& counter)
: m_counter(counter)
{}
private:
virtual void handleMessage(MessageInterruptTasks* message)
{
m_counter++;
}
size_t& m_counter;
};
m_listener = std::make_shared<InterruptListener>(m_count);
}
MessageInterruptTasksCounter::~MessageInterruptTasksCounter()
{
}
void MessageInterruptTasksCounter::reset()
{
m_count = 0;
}
size_t MessageInterruptTasksCounter::getCount() const
{
return m_count;
}
@@ -1,23 +0,0 @@
#ifndef MESSAGE_INTERRUPT_TASKS_COUNTER_H
#define MESSAGE_INTERRUPT_TASKS_COUNTER_H
#include <memory>
class MessageListenerBase;
class MessageInterruptTasksCounter
{
public:
MessageInterruptTasksCounter();
virtual ~MessageInterruptTasksCounter();
void reset();
size_t getCount() const;
private:
std::shared_ptr<MessageListenerBase> m_listener;
size_t m_count;
};
#endif // MESSAGE_INTERRUPT_TASKS_COUNTER_H
+2 -4
View File
@@ -140,8 +140,7 @@ void MessageQueue::startMessageLoop()
}
}
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
{
@@ -176,8 +175,7 @@ void MessageQueue::stopMessageLoop()
}
}
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
}
@@ -35,8 +35,7 @@ void TaskGroupParallel::doEnter(std::shared_ptr<Blackboard> blackboard)
Task::TaskState TaskGroupParallel::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
if (m_tasks.size() != 0 && getActiveTaskCount() > 0)
{
+2 -4
View File
@@ -71,8 +71,7 @@ void TaskScheduler::startSchedulerLoop()
}
}
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
{
@@ -107,8 +106,7 @@ void TaskScheduler::stopSchedulerLoop()
}
}
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
}
+16 -3
View File
@@ -1,8 +1,20 @@
#include "IndexerCxx.h"
#include "CxxParser.h"
#include "ParserClientImpl.h"
#include "FileRegister.h"
#include "IndexerStateInfo.h"
#include "ParserClientImpl.h"
IndexerCxx::IndexerCxx()
: m_indexerStateInfo(std::make_shared<IndexerStateInfo>())
{
m_indexerStateInfo->indexingInterrupted = false;
}
void IndexerCxx::interrupt()
{
m_indexerStateInfo->indexingInterrupted = true;
}
std::shared_ptr<IntermediateStorage> IndexerCxx::doIndex(std::shared_ptr<IndexerCommandCxx> indexerCommand)
{
@@ -12,7 +24,8 @@ std::shared_ptr<IntermediateStorage> IndexerCxx::doIndex(std::shared_ptr<Indexer
parserClient,
std::make_shared<FileRegister>(
indexerCommand->getSourceFilePath(), indexerCommand->getIndexedPaths(), indexerCommand->getExcludeFilters()
)
),
m_indexerStateInfo
);
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
@@ -31,7 +44,7 @@ std::shared_ptr<IntermediateStorage> IndexerCxx::doIndex(std::shared_ptr<Indexer
storage->setFilesWithErrorsIncomplete();
}
if (IndexerBase::interrupted())
if (m_indexerStateInfo->indexingInterrupted)
{
return std::shared_ptr<IntermediateStorage>();
}
+10 -1
View File
@@ -2,14 +2,23 @@
#define INDEXER_CXX_H
#include <memory>
#include <mutex>
#include "IndexerCommandCxx.h"
#include "Indexer.h"
#include "IndexerCommandCxx.h"
struct IndexerStateInfo;
class IndexerCxx: public Indexer<IndexerCommandCxx>
{
public:
IndexerCxx();
void interrupt() override;
private:
std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<IndexerCommandCxx> indexerCommand) override;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
};
#endif // INDEXER_CXX_H
+5 -2
View File
@@ -18,10 +18,12 @@ class ASTAction
public:
explicit ASTAction(
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
)
: m_client(client)
, m_canonicalFilePathCache(canonicalFilePathCache)
, m_indexerStateInfo(indexerStateInfo)
, m_commentHandler(client, canonicalFilePathCache)
{}
@@ -31,7 +33,7 @@ protected:
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile) override
{
return std::unique_ptr<clang::ASTConsumer>(
new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_canonicalFilePathCache));
new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_canonicalFilePathCache, m_indexerStateInfo));
}
virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler) override
@@ -46,6 +48,7 @@ protected:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
CommentHandler m_commentHandler;
};
@@ -6,10 +6,12 @@
ASTActionFactory::ASTActionFactory(
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
)
: m_client(client)
, m_canonicalFilePathCache(canonicalFilePathCache)
, m_indexerStateInfo(indexerStateInfo)
{
}
@@ -19,5 +21,5 @@ ASTActionFactory::~ASTActionFactory()
clang::FrontendAction* ASTActionFactory::create()
{
return new ASTAction<clang::ASTFrontendAction>(m_client, m_canonicalFilePathCache);
return new ASTAction<clang::ASTFrontendAction>(m_client, m_canonicalFilePathCache, m_indexerStateInfo);
}
@@ -1,8 +1,12 @@
#ifndef AST_ACTION_FACTORY
#define AST_ACTION_FACTORY
#include <memory>
#include <clang/Tooling/Tooling.h>
#include "IndexerStateInfo.h"
class CanonicalFilePathCache;
class ParserClient;
@@ -12,7 +16,8 @@ class ASTActionFactory
public:
explicit ASTActionFactory(
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
);
virtual ~ASTActionFactory();
@@ -22,6 +27,7 @@ public:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
};
#endif // AST_ACTION_FACTORY
+4 -3
View File
@@ -8,18 +8,19 @@ ASTConsumer::ASTConsumer(
clang::ASTContext* context,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
)
{
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
if (appSettings->getLoggingEnabled() && appSettings->getVerboseIndexerLoggingEnabled())
{
m_visitor = std::make_shared<CxxVerboseAstVisitor>(context, preprocessor, client, canonicalFilePathCache);
m_visitor = std::make_shared<CxxVerboseAstVisitor>(context, preprocessor, client, canonicalFilePathCache, indexerStateInfo);
}
else
{
m_visitor = std::make_shared<CxxAstVisitor>(context, preprocessor, client, canonicalFilePathCache);
m_visitor = std::make_shared<CxxAstVisitor>(context, preprocessor, client, canonicalFilePathCache, indexerStateInfo);
}
}
+4 -1
View File
@@ -7,6 +7,7 @@
class CanonicalFilePathCache;
class CxxAstVisitor;
class ParserClient;
struct IndexerStateInfo;
class ASTConsumer
: public clang::ASTConsumer
@@ -16,7 +17,8 @@ public:
clang::ASTContext* context,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
);
virtual ~ASTConsumer();
@@ -25,6 +27,7 @@ public:
private:
std::shared_ptr<CxxAstVisitor> m_visitor;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
};
#endif // AST_CONSUMER_H
+15 -7
View File
@@ -3,32 +3,34 @@
#include <clang/AST/ASTContext.h>
#include <clang/Lex/Preprocessor.h>
#include "CanonicalFilePathCache.h"
#include "CxxDeclNameResolver.h"
#include "CxxTypeNameResolver.h"
#include "CanonicalFilePathCache.h"
#include "utilityClang.h"
#include "IndexerStateInfo.h"
#include "logging.h"
#include "ParserClient.h"
#include "ParseLocation.h"
#include "utilityClang.h"
#include "utilityString.h"
CxxAstVisitor::CxxAstVisitor(
clang::ASTContext* astContext,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
)
: m_astContext(astContext)
, m_preprocessor(preprocessor)
, m_client(client)
, m_indexerStateInfo(indexerStateInfo)
, m_canonicalFilePathCache(canonicalFilePathCache)
, m_contextComponent(this)
, m_declRefKindComponent(this)
, m_typeRefKindComponent(this)
, m_implicitCodeComponent(this)
, m_indexerComponent(this, astContext, client)
, m_braceRecorderComponent(this, astContext, client)
, m_canonicalFilePathCache(canonicalFilePathCache)
, m_declNameCache([&](const clang::NamedDecl* decl) -> NameHierarchy
{
if (decl)
@@ -99,6 +101,7 @@ CanonicalFilePathCache* CxxAstVisitor::getCanonicalFilePathCache()
void CxxAstVisitor::indexDecl(clang::Decl* d)
{
LOG_INFO("starting AST traversal");
this->TraverseDecl(d);
}
@@ -194,7 +197,12 @@ bool CxxAstVisitor::TraverseDecl(clang::Decl* decl)
FOREACH_COMPONENT(endTraverseDecl(decl));
}
return m_interruptCounter.getCount() == 0;
if (m_indexerStateInfo && m_indexerStateInfo->indexingInterrupted)
{
LOG_INFO("interrupting AST traversal");
return false;
}
return true;
}
// same as Base::TraverseQualifiedTypeLoc(..) but we need to make sure to call this.TraverseTypeLoc(..)
+6 -7
View File
@@ -5,8 +5,6 @@
#include <clang/AST/RecursiveASTVisitor.h>
#include "MessageInterruptTasksCounter.h"
#include "CxxAstVisitorComponentBraceRecorder.h"
#include "CxxAstVisitorComponentContext.h"
#include "CxxAstVisitorComponentDeclRefKind.h"
@@ -17,9 +15,10 @@
class CanonicalFilePathCache;
class ParserClient;
struct ParseLocation;
class FilePath;
struct IndexerStateInfo;
struct ParseLocation;
// methods are called in this order:
// TraverseDecl()
@@ -40,7 +39,8 @@ public:
clang::ASTContext* astContext,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
);
virtual ~CxxAstVisitor() = default;
@@ -159,6 +159,8 @@ private:
clang::ASTContext* m_astContext;
clang::Preprocessor* m_preprocessor;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
CxxAstVisitorComponentContext m_contextComponent;
CxxAstVisitorComponentDeclRefKind m_declRefKindComponent;
@@ -167,9 +169,6 @@ private:
CxxAstVisitorComponentIndexer m_indexerComponent;
CxxAstVisitorComponentBraceRecorder m_braceRecorderComponent;
MessageInterruptTasksCounter m_interruptCounter;
std::shared_ptr<CanonicalFilePathCache> m_canonicalFilePathCache;
DeclNameCache m_declNameCache;
TypeNameCache m_typeNameCache;
};
+8 -3
View File
@@ -130,9 +130,14 @@ namespace
}
}
CxxParser::CxxParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
CxxParser::CxxParser(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
)
: Parser(client)
, m_fileRegister(fileRegister)
, m_indexerStateInfo(indexerStateInfo)
{
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmParser();
@@ -161,7 +166,7 @@ void CxxParser::buildIndex(const std::wstring& fileName, std::shared_ptr<TextAcc
std::make_shared<CanonicalFilePathCache>(m_fileRegister);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(FilePath(), canonicalFilePathCache, false);
ASTActionFactory actionFactory(m_client, canonicalFilePathCache);
ASTActionFactory actionFactory(m_client, canonicalFilePathCache, m_indexerStateInfo);
std::vector<std::string> args = getCommandlineArgumentsEssential(compilerFlags);
@@ -191,7 +196,7 @@ void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase
LOG_INFO("Clang Invocation errors: " + info.errors);
}
ASTActionFactory actionFactory(m_client, canonicalFilePathCache);
ASTActionFactory actionFactory(m_client, canonicalFilePathCache, m_indexerStateInfo);
tool.run(&actionFactory);
}
+4 -1
View File
@@ -21,10 +21,12 @@ namespace clang {
}
}
struct IndexerStateInfo;
class CxxParser: public Parser
{
public:
CxxParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
CxxParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister, std::shared_ptr<IndexerStateInfo> indexerStateInfo);
void buildIndex(std::shared_ptr<IndexerCommandCxx> indexerCommand);
void buildIndex(const std::wstring& fileName, std::shared_ptr<TextAccess> fileContent, std::vector<std::wstring> compilerFlags = {});
@@ -40,6 +42,7 @@ private:
friend class TaskParseCxx;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
};
@@ -15,18 +15,15 @@ CxxVerboseAstVisitor::CxxVerboseAstVisitor(
clang::ASTContext* context,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
)
: base(context, preprocessor, client, canonicalFilePathCache)
: base(context, preprocessor, client, canonicalFilePathCache, indexerStateInfo)
, m_currentFilePath(L"")
, m_indentation(0)
{
}
CxxVerboseAstVisitor::~CxxVerboseAstVisitor()
{
}
bool CxxVerboseAstVisitor::TraverseDecl(clang::Decl* d)
{
if (d)
@@ -16,11 +16,10 @@ public:
clang::ASTContext* context,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache,
std::shared_ptr<IndexerStateInfo> indexerStateInfo
);
virtual ~CxxVerboseAstVisitor();
private:
typedef CxxAstVisitor base;
+3 -6
View File
@@ -298,8 +298,7 @@ DatabasePolicy QtDialogView::finishedIndexingDialog(
while (!m_resultReady)
{
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
return policy;
@@ -338,8 +337,7 @@ int QtDialogView::confirm(const std::string& message, const std::vector<std::str
while (!m_resultReady)
{
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
return result;
@@ -378,8 +376,7 @@ int QtDialogView::confirm(const std::wstring& message, const std::vector<std::ws
while (!m_resultReady)
{
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
return result;
+15 -3
View File
@@ -1,19 +1,31 @@
#include "IndexerJava.h"
#include "IndexerCommandJava.h"
#include "ParserClientImpl.h"
#include "IndexerStateInfo.h"
#include "JavaParser.h"
#include "ParserClientImpl.h"
IndexerJava::IndexerJava()
: m_indexerStateInfo(std::make_shared<IndexerStateInfo>())
{
m_indexerStateInfo->indexingInterrupted = false;
}
IndexerJava::~IndexerJava()
{
JavaParser::clearCaches();
}
void IndexerJava::interrupt()
{
m_indexerStateInfo->indexingInterrupted = true;
}
std::shared_ptr<IntermediateStorage> IndexerJava::doIndex(std::shared_ptr<IndexerCommandJava> indexerCommand)
{
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient);
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient, m_indexerStateInfo);
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
parserClient->setStorage(storage);
@@ -31,7 +43,7 @@ std::shared_ptr<IntermediateStorage> IndexerJava::doIndex(std::shared_ptr<Indexe
storage->setFilesWithErrorsIncomplete();
}
if (interrupted())
if (m_indexerStateInfo->indexingInterrupted)
{
return std::shared_ptr<IntermediateStorage>();
}
+9 -1
View File
@@ -3,14 +3,22 @@
#include <memory>
#include "IndexerCommandJava.h"
#include "Indexer.h"
#include "IndexerCommandJava.h"
struct IndexerStateInfo;
class IndexerJava: public Indexer<IndexerCommandJava>
{
public:
IndexerJava();
virtual ~IndexerJava();
void interrupt() override;
private:
std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<IndexerCommandJava> indexerCommand) override;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
};
#endif // INDEXER_JAVA_H
+10 -8
View File
@@ -2,14 +2,15 @@
#include <jni.h>
#include "NameHierarchy.h"
#include "JavaEnvironmentFactory.h"
#include "ParseLocation.h"
#include "ReferenceKind.h"
#include "ParserClient.h"
#include "ApplicationSettings.h"
#include "TextAccess.h"
#include "IndexerStateInfo.h"
#include "JavaEnvironmentFactory.h"
#include "NameHierarchy.h"
#include "ParseLocation.h"
#include "ParserClient.h"
#include "ReferenceKind.h"
#include "ResourcePaths.h"
#include "TextAccess.h"
#include "utilityJava.h"
#include "utilityString.h"
@@ -29,8 +30,9 @@ void JavaParser::clearCaches()
}
}
JavaParser::JavaParser(std::shared_ptr<ParserClient> client)
JavaParser::JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<IndexerStateInfo> indexerStateInfo)
: Parser(client)
, m_indexerStateInfo(indexerStateInfo)
, m_id(s_nextParserId++)
{
const std::string errorString = utility::prepareJavaEnvironment();
@@ -140,7 +142,7 @@ std::mutex JavaParser::s_parsersMutex;
bool JavaParser::doGetInterrupted()
{
return m_interruptCounter.getCount() > 0;
return m_indexerStateInfo->indexingInterrupted;
}
void JavaParser::doLogInfo(jstring jInfo)
+6 -6
View File
@@ -5,12 +5,12 @@
#include <mutex>
#include <string>
#include "IndexerCommandJava.h"
#include "Parser.h"
#include "JavaEnvironment.h"
#include "FilePath.h"
#include "IndexerCommandJava.h"
#include "IndexerStateInfo.h"
#include "JavaEnvironment.h"
#include "logging.h"
#include "MessageInterruptTasksCounter.h"
#include "Parser.h"
struct JNIEnv_;
typedef JNIEnv_ JNIEnv;
@@ -35,7 +35,7 @@ class JavaParser: public Parser
public:
static void clearCaches();
JavaParser(std::shared_ptr<ParserClient> client);
JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<IndexerStateInfo> indexerStateInfo);
~JavaParser();
void buildIndex(std::shared_ptr<IndexerCommandJava> indexerCommand);
@@ -231,7 +231,7 @@ private:
const int m_id;
FilePath m_currentFilePath;
MessageInterruptTasksCounter m_interruptCounter;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
};
#endif // JAVA_PARSER_H
+1 -1
View File
@@ -176,7 +176,7 @@ private:
std::shared_ptr<DumpParserClient> parserClient = std::make_shared<DumpParserClient>();
CxxParser parser(parserClient, fileRegister);
CxxParser parser(parserClient, fileRegister, std::make_shared<IndexerStateInfo>());
std::shared_ptr<IndexerCommandCxx> command = std::make_shared<IndexerCommandCxx>(
sourceFilePath,
+2 -3
View File
@@ -4128,7 +4128,7 @@ public:
);
std::shared_ptr<TestParserClient> client = std::make_shared<TestParserClient>();
CxxParser parser(client, std::make_shared<TestFileRegister>());
CxxParser parser(client, std::make_shared<TestFileRegister>(), std::make_shared<IndexerStateInfo>());
parser.buildIndex(indexerCommand);
@@ -4398,9 +4398,8 @@ public:
private:
std::shared_ptr<TestParserClient> parseCode(std::string code, std::vector<std::wstring> compilerFlags = {})
{
std::shared_ptr<TestFileRegister> fileRegister = std::make_shared<TestFileRegister>();
std::shared_ptr<TestParserClient> parserClient = std::make_shared<TestParserClient>();
CxxParser parser(parserClient, fileRegister);
CxxParser parser(parserClient, std::make_shared<TestFileRegister>(), std::make_shared<IndexerStateInfo>());
parser.buildIndex(L"input.cc", TextAccess::createFromString(code), utility::concat(compilerFlags, std::vector<std::wstring>(1, L"-std=c++1z")));
return parserClient;
}
+1 -1
View File
@@ -273,7 +273,7 @@ private:
{
std::shared_ptr<DumpParserClient> parserClient = std::make_shared<DumpParserClient>();
JavaParser parser(parserClient);
JavaParser parser(parserClient, std::make_shared<IndexerStateInfo>());
std::shared_ptr<IndexerCommandJava> command = std::make_shared<IndexerCommandJava>(sourceFilePath, L"8", classpath);
TimeStamp startTime = TimeStamp::now();
+1 -1
View File
@@ -1909,7 +1909,7 @@ private:
setupJavaEnvironmentFactory();
JavaParser parser(parserClient);
JavaParser parser(parserClient, std::make_shared<IndexerStateInfo>());
parser.buildIndex(FilePath(L"input.cc"), textAccess);
return parserClient;
+3
View File
@@ -1,5 +1,8 @@
#include <cxxtest/TestSuite.h>
#include <memory>
#include <thread>
#include "SharedMemory.h"
class SharedMemoryTestSuite : public CxxTest::TestSuite