-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_dispatcher.cpp
More file actions
105 lines (89 loc) · 1.75 KB
/
Copy pathtask_dispatcher.cpp
File metadata and controls
105 lines (89 loc) · 1.75 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "../include/dispatch_queue/task_dispatcher.hpp"
#include "../include/dispatch_queue/thread_name.hpp"
namespace dispatch_queue {
task_dispatcher::task_dispatcher()
{
}
task_dispatcher::task_dispatcher(int thread_count, const std::string& name_prefix)
: task_dispatcher(thread_count, [name_prefix](int i){
set_thread_name(name_prefix + std::to_string(i));
})
{
}
task_dispatcher::~task_dispatcher() {
shutdown();
}
bool task_dispatcher::is_threaded() const {
return worker_pool != nullptr;
}
int task_dispatcher::thread_count() const {
if (worker_pool) {
return worker_pool->thread_count();
}
else {
return 0;
}
}
size_t task_dispatcher::size() const {
if (worker_pool) {
return worker_pool->size();
}
else {
return 0;
}
}
size_t task_dispatcher::main_size() const {
if (worker_pool) {
return worker_pool->main_size();
}
else {
return task_queue.main_size();
}
}
bool task_dispatcher::empty() const {
if (worker_pool) {
return worker_pool->empty();
}
else {
return true;
}
}
bool task_dispatcher::main_empty() const {
if (worker_pool) {
return worker_pool->main_empty();
}
else {
return task_queue.main_empty();
}
}
void task_dispatcher::clear() {
if (worker_pool) {
worker_pool->clear();
}
}
void task_dispatcher::main_clear() {
if (worker_pool) {
worker_pool->main_clear();
}
else {
task_queue.main_clear();
}
}
void task_dispatcher::main_loop(float delta) {
auto main_loop_tasks = worker_pool
? worker_pool->pop_main_loop_tasks(delta)
: task_queue.pop_main_loop_tasks(delta);
for (auto&& it : main_loop_tasks) {
it();
}
}
void task_dispatcher::wait() {
if (worker_pool) {
worker_pool->wait();
}
}
void task_dispatcher::shutdown() {
clear();
worker_pool.reset();
}
} // end namespace dispatch_queue