summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-23 00:30:10 +0100
committerNao Pross <naopross@thearcway.org>2019-01-23 00:30:10 +0100
commitfd9ecd4e9c7cbe76bc60197a7183ac3ca4e8d0f8 (patch)
tree68f5d42aa3aee7ec2519a8766b8619bb73223d6e
parentceh (diff)
downloadflatland-fd9ecd4e9c7cbe76bc60197a7183ac3ca4e8d0f8.tar.gz
flatland-fd9ecd4e9c7cbe76bc60197a7183ac3ca4e8d0f8.zip
Integrate prioritized into task, rename prior_t to priority_t
There was a bunch of code in core/priority.hpp that has been reduced. It works the same as before, just with less stuff. task.cpp is buildable without errors with: $ ninja build/engine/task.o
-rw-r--r--engine/include/core/priority.hpp60
-rw-r--r--engine/include/core/signal.hpp6
-rw-r--r--engine/include/core/task.hpp19
-rw-r--r--engine/signal.cpp6
-rw-r--r--engine/task.cpp11
m---------lib/libmm0
6 files changed, 31 insertions, 71 deletions
diff --git a/engine/include/core/priority.hpp b/engine/include/core/priority.hpp
index 5f03bc9..0f00006 100644
--- a/engine/include/core/priority.hpp
+++ b/engine/include/core/priority.hpp
@@ -2,12 +2,10 @@
#include <set>
-namespace flat
-{
- namespace core
- {
- enum class prior_t : unsigned
- {
+namespace flat {
+ namespace core {
+
+ enum class priority_t : unsigned {
max = 0,
higher = 1,
high = 2,
@@ -17,47 +15,23 @@ namespace flat
min = 6,
};
- class prioritized
- {
- const prior_t m_priority;
+ class prioritized {
+ private:
+ const priority_t m_priority;
public:
+ prioritized(priority_t priority = priority_t::none)
+ : m_priority(priority) {}
- prioritized(prior_t m_priority = prior_t::none) : m_priority(m_priority) {}
-
- const prior priority() const
- {
+ const priority_t priority() const {
return m_priority;
}
- };
-
- struct prior_criteria
- {
- bool operator()(const prioritized& a, const prioritized& b) const
- {
- return a.priority() < b.priority();
- }
- };
-
- /* Compiler will complain if don't pass a non prioritized object */
-
- template <class T>
- using prior_set = std::multiset<T, prior_criteria>;
-
-
- /* Equivalent but with pointers */
-
- struct prior_ptr_criteria
- {
- bool operator()(const prioritized* a, const prioritized* b) const
- {
- return a->priority() < b->priority();
- }
- };
+ };
+
+ bool operator<(const prioritized& lhs, const prioritized& rhs) {
+ return lhs.priority() < rhs.priority();
+ }
+ }
+}
- /* Compiler will complain if don't pass a non prioritized object */
- template <class T>
- using prior_ptr_set = std::multiset<T*, prior_criteria>;
- }
-};
diff --git a/engine/include/core/signal.hpp b/engine/include/core/signal.hpp
index 1057f3f..755f3ed 100644
--- a/engine/include/core/signal.hpp
+++ b/engine/include/core/signal.hpp
@@ -22,12 +22,12 @@ namespace flat
object * sender;
void * data; // TODO, avoid this void pointer
- priority prior;
+ priority_t prior;
signal( object * sender,
const std::string& id = "",
void * data,
- prior_t prior = prior_t::none);
+ priority_t prior = priority_t::none);
/* Alias to flat::core::channel::emit() */
bool emit(const std::string& channel) const;
@@ -51,7 +51,7 @@ namespace flat
public:
- channel(const std::string& id = "", prior_t priority = prior_t::none);
+ channel(const std::string& id = "", priority_t priority = priority_t::none);
~channel();
void emit(const signal&);
diff --git a/engine/include/core/task.hpp b/engine/include/core/task.hpp
index 9422a23..b6ddad1 100644
--- a/engine/include/core/task.hpp
+++ b/engine/include/core/task.hpp
@@ -1,34 +1,25 @@
#pragma once
+#include "priority.hpp"
+
#include <functional>
#include <set>
namespace flat {
namespace core {
- class task {
+ class task : public prioritized {
public:
- enum class priority : unsigned {
- max = 0,
- high = 1,
- none = 2,
- low = 3,
- min = 4,
- };
-
- // to pass a member function (method) use std::bind(f, obj)
- task(std::function<void()> callback, priority p = priority::none);
task() = delete;
+ task(std::function<void()> callback, priority_t p = priority_t::none);
inline void operator()() const { m_callback(); }
- friend bool operator<(const task& lhs, const task& rhs);
private:
- const priority m_priority;
std::function<void()> m_callback;
};
struct job : public std::multiset<task> {
- inline void add_task(task t) {
+ inline auto add_task(task t) {
this->insert(t);
}
diff --git a/engine/signal.cpp b/engine/signal.cpp
index 5f0b356..3804e22 100644
--- a/engine/signal.cpp
+++ b/engine/signal.cpp
@@ -1,11 +1,11 @@
-#include "signal.hpp"
+#include "core/signal.hpp"
using namespace std;
using namespace flat::core;
map<string, channel*> channel::channels;
-channel::channel(const string& id, prior_t prior)
+channel::channel(const string& id, priority_t prior)
{
channel * other = find_channel(id);
@@ -89,7 +89,7 @@ void channel::post_processing()
signal::signal( object *sender,
const string& id,
void *data,
- prior_t priority)
+ priority_t priority)
: sender(sender), data(data), priority(priority)
{
diff --git a/engine/task.cpp b/engine/task.cpp
index c09fa8b..f879530 100644
--- a/engine/task.cpp
+++ b/engine/task.cpp
@@ -1,17 +1,12 @@
-#include "task.hpp"
+#include "core/task.hpp"
#include <functional>
namespace flat {
namespace core {
- bool operator<(const task& lhs, const task& rhs) {
- // task::priority::max is 0, a higher number is lower priority
- return lhs.m_priority < rhs.m_priority;
- }
-
- task::task(std::function<void()> callback, task::priority p)
- : m_priority(p), m_callback(callback) {}
+ task::task(std::function<void()> callback, priority_t p)
+ : m_callback(callback) {}
void job::invoke_tasks() {
for (const task& t : *this) {
diff --git a/lib/libmm b/lib/libmm
-Subproject e6595cf9c527e97198806c48aa0a14ae8e895e8
+Subproject ba03d198b82733043919fda918a80f4bb81800a