summaryrefslogtreecommitdiff
path: root/task.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-18 07:27:57 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-18 08:07:20 +0200
commit80290e7d65dc498e9ea5e64aa6cbc65282072deb (patch)
tree796f723f449d58615c6d81f5eecd212a1e4d0399 /task.cc
parent33addfbf9cc21cd69b3d6476eb0c062bb2c6fcfb (diff)
New dependency system.
Diffstat (limited to 'task.cc')
-rw-r--r--task.cc70
1 files changed, 70 insertions, 0 deletions
diff --git a/task.cc b/task.cc
index e69de29..d539b50 100644
--- a/task.cc
+++ b/task.cc
@@ -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();
+}