| 55 | m_max_concurrent_tasks = max_concurrency; |
| 56 | } |
| 57 | void task_group::execute(task* t) |
| 58 | { |
| 59 | std::unique_lock<std::mutex> lk(m_mtx); |
| 60 | if (m_tasks_running == m_max_concurrent_tasks) |
| 61 | { |
| 62 | /* Queue for later execution by another thread.*/ |
| 63 | m_queue.push(t); |
| 64 | m_total_enqueues++; |
| 65 | return; |
| 66 | } |
| 67 | m_tasks_running++; |
| 68 | for (;;) |
| 69 | { |
| 70 | lk.unlock(); |
| 71 | if (t) |
| 72 | { |
| 73 | t->m_func(t->m_arg); |
| 74 | if (m_enable_task_release) |
| 75 | t->release(); |
| 76 | } |
| 77 | lk.lock(); |
| 78 | m_total_tasks++; |
| 79 | if (m_queue.empty()) |
| 80 | break; |
| 81 | t = m_queue.front(); |
| 82 | m_queue.pop(); |
| 83 | } |
| 84 | m_tasks_running--; |
| 85 | } |
| 86 | |
| 87 | void task_group::cancel_pending(task* t) |
| 88 | { |