-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpending_task_queue.cpp
More file actions
48 lines (38 loc) · 968 Bytes
/
Copy pathpending_task_queue.cpp
File metadata and controls
48 lines (38 loc) · 968 Bytes
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
#include "../include/pending_task_queue.hpp"
namespace dispatch_queue {
namespace detail {
bool pending_task_queue::empty() const {
return background_tasks.empty();
}
size_t pending_task_queue::size() const {
return background_tasks.size();
}
void pending_task_queue::clear() {
background_tasks.clear();
}
void pending_task_queue::push(pending_task&& task, bool run_on_main_loop) {
if (run_on_main_loop) {
main_loop_tasks.push_back(std::move(task));
}
else {
background_tasks.push_back(std::move(task));
}
}
bool pending_task_queue::try_pop(pending_task& task) {
if (!background_tasks.empty()) {
task = std::move(background_tasks.front());
background_tasks.pop_front();
return true;
}
else {
task = {};
return false;
}
}
std::deque<pending_task> pending_task_queue::pop_main_loop_tasks() {
std::deque<pending_task> result;
main_loop_tasks.swap(result);
return result;
}
} // end namespace detail
} // end namespace dispatch_queue