summaryrefslogtreecommitdiffstats
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
parentMerge remote-tracking branch 'nao/raii-task' (diff)
downloadflatland-f5cd19114ef036dd73bd6166235efa1d3c0f657d.tar.gz
flatland-f5cd19114ef036dd73bd6166235efa1d3c0f657d.zip
Task debugging
-rwxr-xr-xbuild/test/task_testbin0 -> 118424 bytes
-rw-r--r--engine/include/serial/focusable.h2
-rw-r--r--engine/object.cpp2
-rw-r--r--engine/task.cpp29
-rw-r--r--ninja/rules.ninja2
-rw-r--r--test/task_test.cpp20
6 files changed, 39 insertions, 16 deletions
diff --git a/build/test/task_test b/build/test/task_test
new file mode 100755
index 0000000..dba86da
--- /dev/null
+++ b/build/test/task_test
Binary files differ
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);
- }
- });
+ }
}
+
}
}
diff --git a/ninja/rules.ninja b/ninja/rules.ninja
index 221e9ca..5897422 100644
--- a/ninja/rules.ninja
+++ b/ninja/rules.ninja
@@ -1,7 +1,7 @@
includes = -I lib/include -I engine/include
cflags = -Wall -pedantic -fPIC -std=c++17 -DDEBUG $includes
-libs = -lSDL2 lib/libmm/build/libmm.a lib/libwsdl2/build/libwsdl2.a
+libs = #-lSDL2 lib/libmm/build/libmm.a lib/libwsdl2/build/libwsdl2.a
lflags = $libs
flags = -fdiagnostics-color
diff --git a/test/task_test.cpp b/test/task_test.cpp
index 199d510..e578bfd 100644
--- a/test/task_test.cpp
+++ b/test/task_test.cpp
@@ -3,9 +3,21 @@
#include <functional>
#include <iostream>
+using namespace flat::core;
// test class
struct message {
+
+ message(job& m_job, bool date)
+ {
+ if (date)
+ mytask = m_job.make_task(std::bind(&message::print_date, *this));
+ else
+ mytask = m_job.make_task(std::bind(&message::print_motd, *this));
+ }
+
+ std::shared_ptr<task> mytask;
+
std::string motd = "today we have no motd!";
std::string date = "1 Jan 1970";
@@ -30,8 +42,6 @@ void ciao() {
int main(int argc, char *argv[]) {
- using namespace flat::core;
-
std::cout << "Testing functions" << std::endl;
std::cout << "should print once: hello!" << std::endl;
@@ -54,13 +64,11 @@ int main(int argc, char *argv[]) {
job m_job;
// test a method
- message m;
- m_job.make_task(std::bind(&message::print_motd, m));
+ message m(m_job, false);
// test a method of an object that goes out of scope
{
- message out;
- m_job.make_task(std::bind(&message::print_date, out));
+ message out(m_job, true);
}
// invoke tasks