summaryrefslogtreecommitdiffstats
path: root/engine
diff options
context:
space:
mode:
authorancarola <raffaele.ancarola@epfl.ch>2019-01-23 16:47:53 +0100
committerancarola <raffaele.ancarola@epfl.ch>2019-01-23 16:47:53 +0100
commitf5cd19114ef036dd73bd6166235efa1d3c0f657d (patch)
treed794685175c9c69fc975e4c9f85bd98d6bf10abe /engine
parentMerge remote-tracking branch 'nao/raii-task' (diff)
downloadflatland-f5cd19114ef036dd73bd6166235efa1d3c0f657d.tar.gz
flatland-f5cd19114ef036dd73bd6166235efa1d3c0f657d.zip
Task debugging
Diffstat (limited to 'engine')
-rw-r--r--engine/include/serial/focusable.h2
-rw-r--r--engine/object.cpp2
-rw-r--r--engine/task.cpp29
3 files changed, 24 insertions, 9 deletions
diff --git a/engine/include/serial/focusable.h b/engine/include/serial/focusable.h
index 4880ff8..008f7a3 100644
--- a/engine/include/serial/focusable.h
+++ b/engine/include/serial/focusable.h
@@ -1,7 +1,7 @@
#ifndef __FOCUSABLE_H__
#define __FOCUSABLE_H__
-#include "object.hpp"
+#include "core/object.hpp"
#include "types.hpp"
class task_s;
diff --git a/engine/object.cpp b/engine/object.cpp
index b6a22fd..7134061 100644
--- a/engine/object.cpp
+++ b/engine/object.cpp
@@ -1,4 +1,4 @@
-#include "object.hpp"
+#include "core/object.hpp"
#include <stdlib.h>
diff --git a/engine/task.cpp b/engine/task.cpp
index f2b6058..7f1b08b 100644
--- a/engine/task.cpp
+++ b/engine/task.cpp
@@ -3,6 +3,11 @@
#include <functional>
#include <memory>
+#include <vector>
+
+#include <iostream>
+
+using namespace std;
namespace flat {
namespace core {
@@ -10,22 +15,32 @@ namespace flat {
: m_callback(f) {}
std::shared_ptr<task> job::make_task(task::callback f, priority_t p) {
+
auto shared = std::make_shared<task>(f, p);
insert(shared);
return shared;
}
void job::invoke_tasks() {
- std::for_each(begin(), end(), [&](auto tp) {
+ //std::for_each(begin(), end(), [&](auto tp) {
+
+ vector<weak_ptr<task>> to_erase;
+
+ for (auto tp : (*this)) {
+ if (tp.expired())
+ to_erase.push_back(tp);
+ }
+
+ for (auto tp : to_erase)
+ erase(tp);
+
+ for (auto tp : (*this)) {
// check that the task has not expired
- if (auto t = tp.lock()) {
// run task
+ auto t = tp.lock();
std::invoke(*t);
- } else {
- // delete task
- erase(tp);
- }
- });
+ }
}
+
}
}