1#include "../include/detail/pending_task_queue.hpp"
7bool pending_task_queue::empty()
const {
8 for (
auto&& it : tagged_tasks) {
9 if (!it.second.empty()) {
13 return background_tasks.empty();
16size_t pending_task_queue::size()
const {
18 for (
auto&& it : tagged_tasks) {
19 count += it.second.size();
21 return count + background_tasks.size();
24void pending_task_queue::clear() {
25 for (
auto&& it : tagged_tasks) {
28 background_tasks.clear();
31bool pending_task_queue::push(task_type type, task_function&& task,
task_tag tag) {
34 main_loop_tasks.push_back({ std::move(task) });
37 case task_type::tagged:
38 if (tag != NULL_TAG) {
39#ifdef __cpp_lib_unordered_map_try_emplace
40 auto pair = tagged_tasks.try_emplace(tag, std::list<pending_task>{});
42 auto pair = tagged_tasks.emplace(tag, std::list<pending_task>{});
46 background_tasks.push_back({ std::move(task), tag });
51 pair.first->second.push_back({ std::move(task), tag });
57 case task_type::background:
58 background_tasks.push_back({ std::move(task), NULL_TAG });
66bool pending_task_queue::try_pop(pending_task& task) {
68 if (previous_tag != NULL_TAG) {
69 auto it = tagged_tasks.find(previous_tag);
70 if (it->second.empty()) {
72 tagged_tasks.erase(it);
76 background_tasks.splice(background_tasks.end(), it->second, it->second.begin());
80 if (!background_tasks.empty()) {
81 task = std::move(background_tasks.front());
82 background_tasks.pop_front();
91std::list<task_function> pending_task_queue::pop_main_loop_tasks() {
92 std::list<task_function> result;
93 main_loop_tasks.swap(result);
Definition when_all.hpp:12
Definition dispatch_queue.hpp:19
int task_tag
Definition task_tag.hpp:12