summaryrefslogtreecommitdiff
path: root/task.cc
diff options
context:
space:
mode:
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();
+}