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

Method RunTasksOnAllExecutors

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

ARROW_ENABLE_THREADING

Source from the content-addressed store, hash-verified

291}
292#else // ARROW_ENABLE_THREADING
293bool SerialExecutor::RunTasksOnAllExecutors() {
294 auto globalState = GetSerialExecutorGlobalState();
295 // if the previously called executor was deleted, ignore last_called_executor
296 if (globalState->last_called_executor != NULL &&
297 globalState->all_executors.count(globalState->last_called_executor) == 0) {
298 globalState->last_called_executor = NULL;
299 }
300 bool run_task = true;
301 bool keep_going = true;
302 while (keep_going) {
303 run_task = false;
304 keep_going = false;
305 for (auto it = globalState->all_executors.begin();
306 it != globalState->all_executors.end(); ++it) {
307 if (globalState->last_called_executor != NULL) {
308 // always rerun loop if we have a last_called_executor, otherwise
309 // we may drop out before every executor has been checked
310 keep_going = true;
311 if (globalState->all_executors.count(globalState->last_called_executor) == 0 ||
312 globalState->last_called_executor == *it) {
313 // found the last one (or it doesn't exist ih the set any more)
314 // now we can start running things
315 globalState->last_called_executor = NULL;
316 }
317 // skip until after we have seen the last executor we called
318 // so that we do things nicely in turn
319 continue;
320 }
321 auto exe = *it;
322 // don't make more reentrant calls inside an
323 // executor than the number of concurrent tasks set on a threadpool, or
324 // 1 in the case of a serialexecutor -
325 // this is because users will expect a serial executor not to be able to
326 // run the next task until the current one is finished (and a threadpool
327 // only to be able to run a certain number of tasks concurrently)
328 if (exe->state_->tasks_running >= exe->state_->max_tasks_running) {
329 continue;
330 }
331 if (exe->state_->paused == false && exe->state_->task_queue.empty() == false) {
332 SerialExecutor* old_exe = globalState->current_executor;
333 globalState->current_executor = exe;
334 Task task = std::move(const_cast<Task&>(exe->state_->task_queue.top().task));
335 exe->state_->task_queue.pop();
336 run_task = true;
337 exe->state_->tasks_running += 1;
338 if (!task.stop_token.IsStopRequested()) {
339 std::move(task.callable)();
340 } else {
341 if (task.stop_callback) {
342 std::move(task.stop_callback)(task.stop_token.Poll());
343 }
344 }
345 exe->state_->tasks_running -= 1;
346 globalState->current_executor = old_exe;
347
348 globalState->last_called_executor = exe;
349 keep_going = false;
350 break;

Callers

nothing calls this directly

Calls 7

IsStopRequestedMethod · 0.80
PollMethod · 0.80
countMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected