blob: 7f1b08bbd5453e0cc32279e04f07be75d1206bff (
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
39
40
41
42
43
44
45
46
|
#include "core/task.hpp"
#include <functional>
#include <memory>
#include <vector>
#include <iostream>
using namespace std;
namespace flat {
namespace core {
task::task(task::callback f, priority_t p)
: 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) {
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
// run task
auto t = tp.lock();
std::invoke(*t);
}
}
}
}
|