-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoinable.hpp
64 lines (45 loc) · 786 Bytes
/
joinable.hpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// === (C) 2020-2024 === parallel_f (tasks, queues, lists in parallel threads)
// Written by Denis Oliver Kropp <Leichenbegatter@outlook.com>
#pragma once
#include <functional>
#include <list>
#include "log.hpp"
namespace parallel_f {
// parallel_f :: task_queue == implementation
class joinable
{
friend class task_queue;
friend class task_list;
private:
std::function<void(void)> join_f;
joinable(std::function<void(void)> join_f)
:
join_f(join_f)
{
}
public:
joinable() {}
public:
void join()
{
LOG_DEBUG("joinable::join()\n");
if (join_f)
join_f();
}
};
class joinables
{
private:
std::list<joinable> list;
public:
void add(joinable joinable)
{
list.push_back(joinable);
}
void join_all()
{
for (auto j : list)
j.join();
}
};
}