| 58 | } |
| 59 | |
| 60 | task_id_t TaskQueue::insertTask(DispatchFunction&& function, |
| 61 | std::chrono::steady_clock::time_point executeTime, |
| 62 | bool isBarrier) { |
| 63 | auto id = ++_taskIdCounter; |
| 64 | |
| 65 | // Keep the tasks sorted by execute time |
| 66 | Task task(id, std::move(function), executeTime, isBarrier); |
| 67 | |
| 68 | auto it = std::upper_bound(_tasks.begin(), _tasks.end(), task, [](const Task& a, const Task& b) { |
| 69 | if (a.executeTime == b.executeTime) { |
| 70 | return a.id < b.id; |
| 71 | } |
| 72 | return a.executeTime < b.executeTime; |
| 73 | }); |
| 74 | |
| 75 | _tasks.emplace(it, std::move(task)); |
| 76 | |
| 77 | return id; |
| 78 | } |
| 79 | |
| 80 | EnqueuedTask TaskQueue::enqueue(Valdi::DispatchFunction function, std::chrono::steady_clock::time_point executeTime) { |
| 81 | EnqueuedTask enqueuedTask; |