MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / TaskLoop

Method TaskLoop

paddle/phi/core/threadpool.cc:76–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76void ThreadPool::TaskLoop() {
77 while (true) {
78 Task task;
79
80 {
81 std::unique_lock<std::mutex> lock(mutex_);
82 scheduled_.wait(
83 lock, [this] { return !this->tasks_.empty() || !this->running_; });
84
85 if (!running_ && tasks_.empty()) {
86 return;
87 }
88
89 if (tasks_.empty()) {
90 PADDLE_THROW(
91 common::errors::Unavailable("Current thread has no task to Run."));
92 }
93
94 // pop a task from the task queue
95 task = std::move(tasks_.front());
96 tasks_.pop();
97 }
98 // run the task
99 task();
100 }
101}
102
103std::unique_ptr<ThreadPool> ThreadPoolIO::io_threadpool_(nullptr);
104std::once_flag ThreadPoolIO::io_init_flag_;

Callers

nothing calls this directly

Calls 4

waitMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected