diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-06-18 07:27:57 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-06-18 08:07:20 +0200 |
commit | 80290e7d65dc498e9ea5e64aa6cbc65282072deb (patch) | |
tree | 796f723f449d58615c6d81f5eecd212a1e4d0399 /task.cc | |
parent | 33addfbf9cc21cd69b3d6476eb0c062bb2c6fcfb (diff) |
New dependency system.
Diffstat (limited to 'task.cc')
-rw-r--r-- | task.cc | 70 |
1 files changed, 70 insertions, 0 deletions
@@ -0,0 +1,70 @@ +#include "task.h" + +#include <unistd.h> +#include <iostream> + +Task::Task(const std::vector<std::string>& depends) + : dependsStr(depends) +{ +} + +void Task::registerDepTasks(const std::list<std::shared_ptr<Task>>& tasks) +{ + for(auto const& depStr : dependsStr) + { + for(const auto& task : tasks) + { + if(task->target() == depStr) + { + dependsTasks.push_back(task); + } + } + } +} + +bool Task::dirty() +{ + for(const auto& task : dependsTasks) + { + if(task->dirty()) + { + return true; + } + } + + return dirtyInner(); +} + +bool Task::ready() +{ + for(const auto& task : dependsTasks) + { + if(task->dirty() && !task->done()) + { + return false; + } + } + + return true; +} + +int Task::run() +{ + if(is_done.load()) + { + return 0; + } + + auto ret = runInner(); + if(ret == 0) + { + is_done.store(true); + } + + return ret; +} + +bool Task::done() const +{ + return is_done.load(); +} |