| 194 | } |
| 195 | |
| 196 | void DoSubmitTask(std::unique_ptr<Task> task) { |
| 197 | Result<Future<>> submit_result = (*task)(); |
| 198 | if (!submit_result.ok()) { |
| 199 | std::unique_lock<std::mutex> lk(mutex_); |
| 200 | running_tasks_--; |
| 201 | AbortUnlocked(submit_result.status(), std::move(lk)); |
| 202 | return; |
| 203 | } |
| 204 | // Capture `task` to keep it alive until finished |
| 205 | if (!submit_result->TryAddCallback([this, task_inner = std::move(task)]() mutable { |
| 206 | return [this, task_inner2 = std::move(task_inner)](const Status& st) mutable { |
| 207 | #ifdef ARROW_WITH_OPENTELEMETRY |
| 208 | TraceTaskFinished(task_inner2.get()); |
| 209 | #endif |
| 210 | // OnTaskFinished might trigger the scheduler to end. We want to ensure that |
| 211 | // is the very last thing that happens after all task destructors have run so |
| 212 | // we eagerly destroy the task first. |
| 213 | task_inner2.reset(); |
| 214 | OnTaskFinished(st); |
| 215 | }; |
| 216 | })) { |
| 217 | return OnTaskFinished(submit_result->status()); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void MaybeEndUnlocked(std::unique_lock<std::mutex>&& lk) { |
| 222 | if (IsFullyFinished()) { |
nothing calls this directly
no test coverage detected