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

Method RunLoop

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

Source from the content-addressed store, hash-verified

257#ifdef ARROW_ENABLE_THREADING
258
259void SerialExecutor::RunLoop() {
260 // This is called from the SerialExecutor's main thread, so the
261 // state is guaranteed to be kept alive.
262 std::unique_lock<std::mutex> lk(state_->mutex);
263 state_->current_thread = std::this_thread::get_id();
264 // If paused we break out immediately. If finished we only break out
265 // when all work is done.
266 while (!state_->paused && !(state_->finished && state_->task_queue.empty())) {
267 // The inner loop is to check if we need to sleep (e.g. while waiting on some
268 // async task to finish from another thread pool). We still need to check paused
269 // because sometimes we will pause even with work leftover when processing
270 // an async generator
271 while (!state_->paused && !state_->task_queue.empty()) {
272 Task task = std::move(const_cast<Task&>(state_->task_queue.top().task));
273 state_->task_queue.pop();
274 lk.unlock();
275 if (!task.stop_token.IsStopRequested()) {
276 std::move(task.callable)();
277 } else {
278 if (task.stop_callback) {
279 std::move(task.stop_callback)(task.stop_token.Poll());
280 }
281 // Can't break here because there may be cleanup tasks down the chain we still
282 // need to run.
283 }
284 lk.lock();
285 }
286 // In this case we must be waiting on work from external (e.g. I/O) executors. Wait
287 // for tasks to arrive (typically via transferred futures).
288 state_->wait_for_tasks.wait(lk, [&] {
289 return state_->paused || state_->finished || !state_->task_queue.empty();
290 });
291 }
292 state_->current_thread = {};
293}
294#else // ARROW_ENABLE_THREADING
295bool SerialExecutor::RunTasksOnAllExecutors() {
296 auto globalState = GetSerialExecutorGlobalState();

Callers 1

NextMethod · 0.45

Calls 4

IsStopRequestedMethod · 0.80
PollMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected