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

Method SpawnReal

cpp/src/arrow/util/thread_pool.cc:149–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147
148#ifdef ARROW_ENABLE_THREADING
149Status SerialExecutor::SpawnReal(TaskHints hints, FnOnce<void()> task,
150 StopToken stop_token, StopCallback&& stop_callback) {
151# ifdef ARROW_WITH_OPENTELEMETRY
152 // Wrap the task to propagate a parent tracing span to it
153 // XXX should there be a generic utility in tracing_internal.h for this?
154 task = [func = std::move(task),
155 active_span =
156 ::arrow::internal::tracing::GetTracer()->GetCurrentSpan()]() mutable {
157 auto scope = ::arrow::internal::tracing::GetTracer()->WithActiveSpan(active_span);
158 std::move(func)();
159 };
160# endif
161 // While the SerialExecutor runs tasks synchronously on its main thread,
162 // SpawnReal may be called from external threads (e.g. when transferring back
163 // from blocking I/O threads), so we need to keep the state alive *and* to
164 // lock its contents.
165 //
166 // Note that holding the lock while notifying the condition variable may
167 // not be sufficient, as some exit paths in the main thread are unlocked.
168 auto state = state_;
169 {
170 std::lock_guard<std::mutex> lk(state->mutex);
171 if (state_->finished) {
172 return Status::Invalid(
173 "Attempt to schedule a task on a serial executor that has already finished or "
174 "been abandoned");
175 }
176 state->task_queue.push(
177 QueuedTask{{std::move(task), std::move(stop_token), std::move(stop_callback)},
178 hints.priority,
179 state_->spawned_tasks_count_++});
180 }
181 state->wait_for_tasks.notify_one();
182 return Status::OK();
183}
184
185void SerialExecutor::Finish() {
186 auto state = state_;

Callers

nothing calls this directly

Calls 5

GetTracerFunction · 0.85
InvalidFunction · 0.50
OKFunction · 0.50
pushMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected