logic: reimplemented task system to abort ast visiting

* reimplemented interrupting TaskParseCxx by adding a listener for the MessageInterruptTask and returning a failure status code on update. This cancels the parent sequence task which results in the indexed items not getting inserted into the persistent storage
* removed the capability for interrupting from TaskScheduler
* changed task system to be closer to the standard behavior tree implementation
* changed task system to accommodate the 3 status return types: Running, Success and Failure
* made TaskGroupSequential fail once a member task fails
* made TaskGroupParallel fail once a member task fails
* split TaskParse... into one task for indexing and one task for injecting
* added TaskRunner that handles updating and resetting the managed task
* fixed numbers that are shown as parsed file count in indexing ui
* fixed deadlock that originated from interaction between TaskScheduler and MessageQueue (one thread wanted to destroy a message listener on a task while the other one wanted to send as message as a task)
This commit is contained in:
malte_langkabel
2016-09-07 14:39:34 +02:00
parent cbcf56f7dc
commit 4f302b0d1d
48 changed files with 651 additions and 678 deletions
+17
View File
@@ -12,6 +12,23 @@ IntermediateStorage::~IntermediateStorage()
{
}
void IntermediateStorage::clear()
{
m_fileNamesToIds.clear();
m_fileIdsToData.clear();
m_nodeNamesToIds.clear();
m_nodeIdsToData.clear();
m_edgeNamesToIds.clear();
m_edgeIdsToData.clear();
m_localSymbolNamesToIds.clear();
m_localSymbolIdsToData.clear();
m_sourceLocations.clear();
m_componentAccesses.clear();
m_commentLocations.clear();
m_errors.clear();
m_nextId = 1;
}
Id IntermediateStorage::addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime)
{
std::shared_ptr<StorageFile> file = std::make_shared<StorageFile>(0, name, filePath, modificationTime);
+2 -2
View File
@@ -14,6 +14,8 @@ public:
IntermediateStorage();
virtual ~IntermediateStorage();
void clear();
virtual Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime);
virtual Id addNode(int type, const std::string& serializedName, int definitionType);
virtual Id addEdge(int type, Id sourceId, Id targetId);
@@ -56,8 +58,6 @@ private:
std::vector<StorageCommentLocation> m_commentLocations;
std::vector<StorageError> m_errors;
std::unordered_map<Id, Id> m_nodeIdsToMemberEdgeIds;
Id m_nextId;
};
+12 -11
View File
@@ -15,20 +15,11 @@ Storage::~Storage()
{
}
void Storage::startInjection()
{
// may be implemented in derived
}
void Storage::finishInjection()
{
// may be implemented in derived
}
void Storage::inject(Storage* injected)
{
TRACE();
std::lock_guard<std::mutex> lock(m_dataMutex);
TRACE();
startInjection();
std::unordered_map<Id, Id> injectedIdToOwnId;
@@ -180,3 +171,13 @@ void Storage::inject(Storage* injected)
finishInjection();
}
void Storage::startInjection()
{
// may be implemented in derived
}
void Storage::finishInjection()
{
// may be implemented in derived
}
+6 -1
View File
@@ -2,6 +2,7 @@
#define STORAGE_H
#include <functional>
#include <mutex>
#include <string>
#include "data/name/NameHierarchy.h"
@@ -32,9 +33,13 @@ public:
virtual void forEachCommentLocation(std::function<void(const StorageCommentLocation& /*data*/)> callback) const = 0;
virtual void forEachError(std::function<void(const StorageError& /*data*/)> callback) const = 0;
void inject(Storage* injected);
private:
virtual void startInjection();
virtual void finishInjection();
void inject(Storage* injected);
std::mutex m_dataMutex;
};
#endif // STORAGE_H
+5 -13
View File
@@ -12,33 +12,25 @@ TaskCleanStorage::TaskCleanStorage(
{
}
void TaskCleanStorage::enter()
void TaskCleanStorage::doEnter()
{
m_dialogView->showProgressDialog("Clearing Files", std::to_string(m_filePaths.size()) + " Files");
}
Task::TaskState TaskCleanStorage::update()
Task::TaskState TaskCleanStorage::doUpdate()
{
m_storage->clearFileElements(m_filePaths);
m_filePaths.clear();
return Task::STATE_FINISHED;
return STATE_SUCCESS;
}
void TaskCleanStorage::exit()
void TaskCleanStorage::doExit()
{
m_dialogView->hideProgressDialog();
}
void TaskCleanStorage::interrupt()
{
}
void TaskCleanStorage::revert()
{
}
void TaskCleanStorage::abort()
void TaskCleanStorage::doReset()
{
}
+6 -9
View File
@@ -19,18 +19,15 @@ public:
DialogView* dialogView
);
virtual void enter();
virtual TaskState update();
virtual void exit();
virtual void interrupt();
virtual void revert();
virtual void abort();
private:
virtual void doEnter();
virtual TaskState doUpdate();
virtual void doExit();
virtual void doReset();
PersistentStorage* m_storage;
std::vector<FilePath> m_filePaths;
DialogView* m_dialogView;
};
#endif // TASK_PARSE_CXX_H
#endif // TASK_CLEAN_STORAGE_H
+30
View File
@@ -0,0 +1,30 @@
#include "data/TaskInjectStorage.h"
#include "data/Storage.h"
TaskInjectStorage::TaskInjectStorage(
std::shared_ptr<Storage> source,
std::shared_ptr<Storage> target
)
: m_source(source)
, m_target(target)
{
}
void TaskInjectStorage::doEnter()
{
}
Task::TaskState TaskInjectStorage::doUpdate()
{
m_target->inject(m_source.get());
return STATE_SUCCESS;
}
void TaskInjectStorage::doExit()
{
}
void TaskInjectStorage::doReset()
{
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef TASK_INJECT_STORAGE_H
#define TASK_INJECT_STORAGE_H
#include <vector>
#include "utility/scheduling/Task.h"
class Storage;
class TaskInjectStorage
: public Task
{
public:
TaskInjectStorage(
std::shared_ptr<Storage> source,
std::shared_ptr<Storage> target
);
private:
virtual void doEnter();
virtual TaskState doUpdate();
virtual void doExit();
virtual void doReset();
std::shared_ptr<Storage> m_source;
std::shared_ptr<Storage> m_target;
};
#endif // TASK_INJECT_STORAGE_H
@@ -0,0 +1,47 @@
#include "data/TaskRepeatWhileUnparsedSourceFilesAvailable.h"
#include "utility/file/FileRegister.h"
TaskRepeatWhileUnparsedSourceFilesAvailable::TaskRepeatWhileUnparsedSourceFilesAvailable(
std::shared_ptr<FileRegister> fileRegister
)
: m_fileRegister(fileRegister)
{
}
void TaskRepeatWhileUnparsedSourceFilesAvailable::setTask(std::shared_ptr<Task> task)
{
if (task)
{
m_taskRunner = std::make_shared<TaskRunner>(task);
}
}
void TaskRepeatWhileUnparsedSourceFilesAvailable::doEnter()
{
}
Task::TaskState TaskRepeatWhileUnparsedSourceFilesAvailable::doUpdate()
{
TaskState state = m_taskRunner->update();
if (state == Task::STATE_SUCCESS)
{
if(m_fileRegister->getUnparsedSourceFilePaths().size() != 0)
{
state = Task::STATE_RUNNING;
m_taskRunner->reset();
}
}
return state;
}
void TaskRepeatWhileUnparsedSourceFilesAvailable::doExit()
{
}
void TaskRepeatWhileUnparsedSourceFilesAvailable::doReset()
{
m_taskRunner->reset();
}
@@ -0,0 +1,31 @@
#ifndef TASK_REPEAT_WHILE_UNPARSED_SOURCE_FILES_AVAILABLE_H
#define TASK_REPEAT_WHILE_UNPARSED_SOURCE_FILES_AVAILABLE_H
#include <vector>
#include "utility/scheduling/TaskDecorator.h"
#include "utility/scheduling/TaskRunner.h"
class FileRegister;
class TaskRepeatWhileUnparsedSourceFilesAvailable
: public TaskDecorator
{
public:
TaskRepeatWhileUnparsedSourceFilesAvailable(
std::shared_ptr<FileRegister> fileRegister
);
virtual void setTask(std::shared_ptr<Task> task);
private:
virtual void doEnter();
virtual TaskState doUpdate();
virtual void doExit();
virtual void doReset();
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<TaskRunner> m_taskRunner;
};
#endif // TASK_REPEAT_WHILE_UNPARSED_SOURCE_FILES_AVAILABLE_H
+15 -12
View File
@@ -9,11 +9,13 @@
#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"
class CxxParser;
class DialogView;
class FileRegister;
class PersistentStorage;
class IntermediateStorage;
namespace clang
{
@@ -25,28 +27,27 @@ namespace clang
class TaskParseCxx
: public Task
, public MessageListener<MessageInterruptTasks>
{
public:
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
TaskParseCxx(
PersistentStorage* storage,
std::shared_ptr<std::mutex> storageMutex,
std::shared_ptr<IntermediateStorage> storage,
std::shared_ptr<FileRegister> fileRegister,
const Parser::Arguments& arguments,
DialogView* dialogView
);
virtual void enter();
virtual TaskState update();
virtual void exit();
virtual void interrupt();
virtual void revert();
virtual void abort();
private:
PersistentStorage* m_storage;
virtual void doEnter();
virtual TaskState doUpdate();
virtual void doExit();
virtual void doReset();
virtual void handleMessage(MessageInterruptTasks* message);
std::shared_ptr<IntermediateStorage> m_storage;
std::shared_ptr<std::mutex> m_storageMutex;
const Parser::Arguments m_arguments;
@@ -57,6 +58,8 @@ private:
bool m_isCDB;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> m_cdb;
bool m_interrupted;
};
#endif // TASK_PARSE_CXX_H
+9 -7
View File
@@ -5,6 +5,8 @@
#include "data/parser/Parser.h"
#include "data/parser/ParserClientImpl.h"
#include "utility/scheduling/Task.h"
#include "utility/scheduling/TaskRunner.h"
#include "utility/scheduling/TaskDecorator.h"
#include "utility/TimePoint.h"
@@ -23,20 +25,20 @@ public:
);
virtual ~TaskParseWrapper();
virtual void enter();
virtual TaskState update();
virtual void exit();
virtual void interrupt();
virtual void revert();
virtual void abort();
virtual void setTask(std::shared_ptr<Task> task);
private:
virtual void doEnter();
virtual TaskState doUpdate();
virtual void doExit();
virtual void doReset();
PersistentStorage* m_storage;
std::shared_ptr<FileRegister> m_fileRegister;
DialogView* m_dialogView;
TimePoint m_start;
std::shared_ptr<TaskRunner> m_taskRunner;
};
#endif // TASK_PARSE_WRAPPER_H
+15 -13
View File
@@ -5,37 +5,39 @@
#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 PersistentStorage;
class IntermediateStorage;
class TaskParseJava
: public Task
, public MessageListener<MessageInterruptTasks>
{
public:
TaskParseJava(
PersistentStorage* storage,
std::shared_ptr<std::mutex> storageMutex,
std::shared_ptr<IntermediateStorage> storage,
std::shared_ptr<FileRegister> fileRegister,
const Parser::Arguments& arguments,
DialogView* dialogView
);
virtual void enter();
virtual TaskState update();
virtual void exit();
virtual void interrupt();
virtual void revert();
virtual void abort();
private:
PersistentStorage* m_storage;
std::shared_ptr<std::mutex> m_storageMutex;
virtual void doEnter();
virtual TaskState doUpdate();
virtual void doExit();
virtual void doReset();
virtual void handleMessage(MessageInterruptTasks* message);
std::shared_ptr<IntermediateStorage> m_storage;
std::shared_ptr<FileRegister> m_fileRegister;
Parser::Arguments m_arguments;
DialogView* m_dialogView;
bool m_interrupted;
};
#endif // TASK_PARSE_JAVA_H