blob: 9422a23cc7d17435c7e121b9f20fa9da465d53db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#pragma once
#include <functional>
#include <set>
namespace flat {
namespace core {
class task {
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;
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) {
this->insert(t);
}
void invoke_tasks();
};
}
}
|