MCPcopy Create free account
hub / github.com/apache/arrow / AddTask

Method AddTask

cpp/src/arrow/util/async_util.cc:302–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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(); }

Callers

nothing calls this directly

Calls 11

ContinueTasksMethod · 0.95
TraceTaskQueuedFunction · 0.85
SubmitTaskClass · 0.85
EmptyMethod · 0.45
PushMethod · 0.45
costMethod · 0.45
CapacityMethod · 0.45
TryAcquireMethod · 0.45
getMethod · 0.45
AddCallbackMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected