| 177 | } |
| 178 | |
| 179 | std::shared_ptr<ScheduledTask> TaskScheduler::getTaskAndRegister() { |
| 180 | if (taskQueue.empty()) { |
| 181 | return nullptr; |
| 182 | } |
| 183 | auto it = taskQueue.begin(); |
| 184 | while (it != taskQueue.end()) { |
| 185 | auto task = (*it)->task; |
| 186 | if (!task->registerThread()) { |
| 187 | // If we cannot register for a thread it is because of three possibilities: |
| 188 | // (i) maximum number of threads have registered for task and the task is completed |
| 189 | // without an exception; or (ii) same as (i) but the task has not yet successfully |
| 190 | // completed; or (iii) task has an exception; Only in (i) we remove the task from the |
| 191 | // queue. For (ii) and (iii) we keep the task in queue. Recall erroring tasks need to be |
| 192 | // manually removed. |
| 193 | if (task->isCompletedSuccessfully()) { // option (i) |
| 194 | it = taskQueue.erase(it); |
| 195 | } else { // option (ii) or (iii): keep the task in the queue. |
| 196 | ++it; |
| 197 | } |
| 198 | } else { |
| 199 | return *it; |
| 200 | } |
| 201 | } |
| 202 | return nullptr; |
| 203 | } |
| 204 | |
| 205 | void TaskScheduler::removeErroringTask(uint64_t scheduledTaskID) { |
| 206 | lock_t lck{taskSchedulerMtx}; |
nothing calls this directly
no test coverage detected