logic: Fixed bugs in TaskParse scheduling
* Added TaskParse as base for TaskParseCxx and TaskParseJava * Fixed increment and decrement of indexer_count on blackboard not atomic * Fixed TaskInjectStorage finished before TaskParse started * Fixed project not cleared when refreshing on now empty project * Fixed TaskInjectStorage overheating when nothing to do
This commit is contained in:
@@ -135,9 +135,6 @@ add_files(
|
||||
data/name/NameHierarchy.cpp
|
||||
data/name/NameHierarchy.h
|
||||
|
||||
data/parser/TaskParseWrapper.cpp
|
||||
data/parser/TaskParseWrapper.h
|
||||
|
||||
data/parser/AccessKind.cpp
|
||||
data/parser/AccessKind.h
|
||||
data/parser/ParseLocation.cpp
|
||||
@@ -152,6 +149,10 @@ add_files(
|
||||
data/parser/ReferenceKind.h
|
||||
data/parser/SymbolKind.cpp
|
||||
data/parser/SymbolKind.h
|
||||
data/parser/TaskParse.cpp
|
||||
data/parser/TaskParse.h
|
||||
data/parser/TaskParseWrapper.cpp
|
||||
data/parser/TaskParseWrapper.h
|
||||
|
||||
data/search/SearchIndex.cpp
|
||||
data/search/SearchIndex.h
|
||||
|
||||
+6
-6
@@ -245,9 +245,9 @@ bool Project::buildIndex(bool forceRefresh)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_fileManager.fetchFilePaths(
|
||||
forceRefresh ? std::vector<FileInfo>() : m_storage->getInfoOnAllFiles()
|
||||
);
|
||||
std::vector<FileInfo> fileInfos = m_storage->getInfoOnAllFiles();
|
||||
|
||||
m_fileManager.fetchFilePaths(forceRefresh ? std::vector<FileInfo>() : fileInfos);
|
||||
|
||||
std::set<FilePath> addedFilePaths = m_fileManager.getAddedFilePaths();
|
||||
std::set<FilePath> updatedFilePaths = m_fileManager.getUpdatedFilePaths();
|
||||
@@ -279,7 +279,7 @@ bool Project::buildIndex(bool forceRefresh)
|
||||
utility::append(filesToParse, addedFilePaths);
|
||||
utility::append(filesToParse, updatedFilePaths);
|
||||
|
||||
if (!filesToClean.size() && !filesToParse.size())
|
||||
if (!filesToClean.size() && !filesToParse.size() && (!forceRefresh || !fileInfos.size()))
|
||||
{
|
||||
MessageStatus("Nothing to refresh, all files are up-to-date.").dispatch();
|
||||
return false;
|
||||
@@ -315,7 +315,7 @@ bool Project::buildIndex(bool forceRefresh)
|
||||
);
|
||||
}
|
||||
|
||||
const int indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
|
||||
const size_t indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
|
||||
|
||||
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(&m_fileManager, indexerThreadCount > 1);
|
||||
|
||||
@@ -334,7 +334,7 @@ bool Project::buildIndex(bool forceRefresh)
|
||||
|
||||
std::shared_ptr<StorageProvider> storageProvider = std::make_shared<StorageProvider>();
|
||||
|
||||
for (int i = 0; i < indexerThreadCount; i++)
|
||||
for (size_t i = 0; i < indexerThreadCount && i < filesToParse.size(); i++)
|
||||
{
|
||||
std::shared_ptr<TaskRepeatWhileSuccess> taskRepeat = std::make_shared<TaskRepeatWhileSuccess>(Task::STATE_SUCCESS);
|
||||
taskParallelIndexing->addTask(taskRepeat);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "data/TaskInjectStorage.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "data/Storage.h"
|
||||
#include "data/StorageProvider.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
@@ -10,11 +13,26 @@ TaskInjectStorage::TaskInjectStorage(
|
||||
)
|
||||
: m_storageProvider(storageProvider)
|
||||
, m_target(target)
|
||||
, m_hasInjected(false)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskInjectStorage::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
while (!m_hasInjected)
|
||||
{
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
if (indexerCount > 0 || m_storageProvider->getStorageCount() > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
}
|
||||
}
|
||||
|
||||
Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
@@ -25,14 +43,20 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr<Blackboard> blackboa
|
||||
if (source)
|
||||
{
|
||||
m_target->inject(source.get());
|
||||
m_hasInjected = true;
|
||||
return STATE_SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
}
|
||||
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
if (indexerCount > 0)
|
||||
if (indexerCount > 0 || m_storageProvider->getStorageCount() > 0)
|
||||
{
|
||||
return STATE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ private:
|
||||
|
||||
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||
std::shared_ptr<Storage> m_target;
|
||||
|
||||
bool m_hasInjected;
|
||||
};
|
||||
|
||||
#endif // TASK_INJECT_STORAGE_H
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "data/parser/TaskParse.h"
|
||||
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
|
||||
TaskParse::TaskParse(
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
const Parser::Arguments& arguments,
|
||||
DialogView* dialogView
|
||||
)
|
||||
: m_storageProvider(storageProvider)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_arguments(arguments)
|
||||
, m_dialogView(dialogView)
|
||||
, m_interrupted(false)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskParse::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(blackboard->getMutex());
|
||||
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount++;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskParse::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(blackboard->getMutex());
|
||||
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount--;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskParse::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskParse::handleMessage(MessageInterruptTasks* message)
|
||||
{
|
||||
m_interrupted = true;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef TASK_PARSE_H
|
||||
#define TASK_PARSE_H
|
||||
|
||||
#include "data/parser/Parser.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/messaging/type/MessageInterruptTasks.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
|
||||
class CxxParser;
|
||||
class DialogView;
|
||||
class FileRegister;
|
||||
class StorageProvider;
|
||||
|
||||
class TaskParse
|
||||
: public Task
|
||||
, public MessageListener<MessageInterruptTasks>
|
||||
{
|
||||
public:
|
||||
TaskParse(
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
const Parser::Arguments& arguments,
|
||||
DialogView* dialogView
|
||||
);
|
||||
|
||||
protected:
|
||||
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||
|
||||
virtual void handleMessage(MessageInterruptTasks* message);
|
||||
|
||||
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
|
||||
const Parser::Arguments m_arguments;
|
||||
DialogView* m_dialogView;
|
||||
|
||||
bool m_interrupted;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_H
|
||||
@@ -13,6 +13,11 @@ Blackboard::~Blackboard()
|
||||
{
|
||||
}
|
||||
|
||||
std::mutex& Blackboard::getMutex()
|
||||
{
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
bool Blackboard::exists(const std::string& key)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_itemMutex);
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
Blackboard(std::shared_ptr<Blackboard> parent);
|
||||
~Blackboard();
|
||||
|
||||
std::mutex& getMutex();
|
||||
|
||||
template <typename T>
|
||||
void set(const std::string& key, const T& value);
|
||||
|
||||
@@ -51,6 +53,8 @@ private:
|
||||
|
||||
std::shared_ptr<Blackboard> m_parent;
|
||||
|
||||
std::mutex m_mutex;
|
||||
|
||||
ItemMap m_items;
|
||||
std::mutex m_itemMutex;
|
||||
};
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#include "data/parser/cxx/TaskParseCxx.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "clang/Tooling/JSONCompilationDatabase.h"
|
||||
|
||||
#include "component/view/DialogView.h"
|
||||
#include "data/parser/cxx/CxxParser.h"
|
||||
#include "data/parser/ParserClientImpl.h"
|
||||
#include "data/StorageProvider.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
std::vector<FilePath> TaskParseCxx::getSourceFilesFromCDB(const FilePath& compilationDatabasePath)
|
||||
{
|
||||
@@ -35,11 +33,8 @@ TaskParseCxx::TaskParseCxx(
|
||||
const Parser::Arguments& arguments,
|
||||
DialogView* dialogView
|
||||
)
|
||||
: m_storageProvider(storageProvider)
|
||||
, m_arguments(arguments)
|
||||
, m_dialogView(dialogView)
|
||||
: TaskParse(storageProvider, fileRegister, arguments, dialogView)
|
||||
, m_isCDB(false)
|
||||
, m_interrupted(false)
|
||||
{
|
||||
if (arguments.compilationDatabasePath.exists())
|
||||
{
|
||||
@@ -51,12 +46,7 @@ TaskParseCxx::TaskParseCxx(
|
||||
|
||||
void TaskParseCxx::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount++;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
TaskParse::doEnter(blackboard);
|
||||
|
||||
if (m_isCDB)
|
||||
{
|
||||
@@ -117,22 +107,3 @@ Task::TaskState TaskParseCxx::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
return (m_interrupted ? STATE_FAILURE : STATE_SUCCESS);
|
||||
}
|
||||
|
||||
void TaskParseCxx::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount--;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskParseCxx::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskParseCxx::handleMessage(MessageInterruptTasks* message)
|
||||
{
|
||||
m_interrupted = true;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
#ifndef TASK_PARSE_CXX_H
|
||||
#define TASK_PARSE_CXX_H
|
||||
|
||||
#include <memory>
|
||||
#include <deque>
|
||||
|
||||
#include "data/parser/Parser.h"
|
||||
#include "data/parser/ParserClientImpl.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/TimePoint.h"
|
||||
#include "utility/messaging/type/MessageInterruptTasks.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "data/parser/TaskParse.h"
|
||||
|
||||
class CxxParser;
|
||||
class DialogView;
|
||||
class FileRegister;
|
||||
class StorageProvider;
|
||||
class ParserClientImpl;
|
||||
|
||||
namespace clang
|
||||
{
|
||||
@@ -25,8 +15,7 @@ namespace clang
|
||||
}
|
||||
|
||||
class TaskParseCxx
|
||||
: public Task
|
||||
, public MessageListener<MessageInterruptTasks>
|
||||
: public TaskParse
|
||||
{
|
||||
public:
|
||||
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
|
||||
@@ -41,23 +30,12 @@ public:
|
||||
private:
|
||||
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||
|
||||
virtual void handleMessage(MessageInterruptTasks* message);
|
||||
|
||||
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||
|
||||
const Parser::Arguments m_arguments;
|
||||
DialogView* m_dialogView;
|
||||
|
||||
std::shared_ptr<CxxParser> m_parser;
|
||||
std::shared_ptr<ParserClientImpl> m_parserClient;
|
||||
|
||||
bool m_isCDB;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> m_cdb;
|
||||
|
||||
bool m_interrupted;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_CXX_H
|
||||
|
||||
@@ -5,10 +5,7 @@
|
||||
#include "data/parser/ParserClientImpl.h"
|
||||
#include "data/StorageProvider.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
TaskParseJava::TaskParseJava(
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
@@ -16,24 +13,10 @@ TaskParseJava::TaskParseJava(
|
||||
const Parser::Arguments& arguments,
|
||||
DialogView* dialogView
|
||||
)
|
||||
: m_storageProvider(storageProvider)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_arguments(arguments)
|
||||
, m_dialogView(dialogView)
|
||||
, m_interrupted(false)
|
||||
: TaskParse(storageProvider, fileRegister, arguments, dialogView)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskParseJava::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount++;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
Task::TaskState TaskParseJava::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
|
||||
@@ -69,22 +52,3 @@ Task::TaskState TaskParseJava::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
return (m_interrupted ? STATE_FAILURE : STATE_SUCCESS);
|
||||
}
|
||||
|
||||
void TaskParseJava::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount--;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskParseJava::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskParseJava::handleMessage(MessageInterruptTasks* message)
|
||||
{
|
||||
m_interrupted = true;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
#ifndef TASK_PARSE_JAVA_H
|
||||
#define TASK_PARSE_JAVA_H
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "data/parser/Parser.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/messaging/type/MessageInterruptTasks.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
|
||||
class DialogView;
|
||||
class FileRegister;
|
||||
class StorageProvider;
|
||||
#include "data/parser/TaskParse.h"
|
||||
|
||||
class TaskParseJava
|
||||
: public Task
|
||||
, public MessageListener<MessageInterruptTasks>
|
||||
: public TaskParse
|
||||
{
|
||||
public:
|
||||
TaskParseJava(
|
||||
@@ -25,19 +15,7 @@ public:
|
||||
);
|
||||
|
||||
private:
|
||||
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||
|
||||
virtual void handleMessage(MessageInterruptTasks* message);
|
||||
|
||||
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
Parser::Arguments m_arguments;
|
||||
DialogView* m_dialogView;
|
||||
|
||||
bool m_interrupted;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_JAVA_H
|
||||
|
||||
Reference in New Issue
Block a user