| 300 | } |
| 301 | |
| 302 | bool AddTask(std::unique_ptr<Task> task) override { |
| 303 | std::unique_lock lk(mutex_); |
| 304 | // If the queue isn't empty then don't even try and acquire the throttle |
| 305 | // We can safely assume it is either blocked or in the middle of trying to |
| 306 | // alert a queued task. |
| 307 | if (!queue_->Empty()) { |
| 308 | queue_->Push(std::move(task)); |
| 309 | return true; |
| 310 | } |
| 311 | int latched_cost = std::min(task->cost(), throttle_->Capacity()); |
| 312 | std::optional<Future<>> maybe_backoff = throttle_->TryAcquire(latched_cost); |
| 313 | if (maybe_backoff) { |
| 314 | #ifdef ARROW_WITH_OPENTELEMETRY |
| 315 | TraceTaskQueued(task.get(), span()); |
| 316 | #endif |
| 317 | queue_->Push(std::move(task)); |
| 318 | lk.unlock(); |
| 319 | maybe_backoff->AddCallback([weak_self = weak_from_this()](const Status& st) { |
| 320 | if (auto self = weak_self.lock(); self && st.ok()) { |
| 321 | self->ContinueTasks(); |
| 322 | } |
| 323 | }); |
| 324 | return true; |
| 325 | } else { |
| 326 | lk.unlock(); |
| 327 | return SubmitTask(std::move(task), latched_cost, /*in_continue=*/false); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | void Pause() override { throttle_->Pause(); } |
| 332 | void Resume() override { throttle_->Resume(); } |
nothing calls this directly
no test coverage detected