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

Method RunLoop

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

Source from the content-addressed store, hash-verified

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