MCPcopy Create free account
hub / github.com/ChunelFeng/CThreadPool / monitor

Method monitor

src/UtilsCtrl/ThreadPool/UThreadPool.cpp:173–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171
172
173CVoid UThreadPool::monitor() {
174 while (is_monitor_) {
175 while (is_monitor_ && !is_init_) {
176 // 如果没有init,则一直处于空跑状态
177 CGRAPH_SLEEP_SECOND(1)
178 }
179
180 int span = config_.monitor_span_;
181 while (is_monitor_ && is_init_ && span--) {
182 CGRAPH_SLEEP_SECOND(1) // 保证可以快速退出
183 }
184
185 // 如果 primary线程都在执行,则表示忙碌
186 bool busy = std::all_of(primary_threads_.begin(), primary_threads_.end(),
187 [](UThreadPrimaryPtr ptr) { return nullptr != ptr && ptr->is_running_; });
188
189 // 如果忙碌或者priority_task_queue_中有任务,则需要添加 secondary线程
190 if (busy || !priority_task_queue_.empty()) {
191 createSecondaryThread(1);
192 }
193
194 // 判断 secondary 线程是否需要退出
195 for (auto iter = secondary_threads_.begin(); iter != secondary_threads_.end(); ) {
196 (*iter)->freeze() ? secondary_threads_.erase(iter++) : iter++;
197 }
198 }
199}
200
201CGRAPH_NAMESPACE_END

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected