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

Method monitor

src/UtilsCtrl/ThreadPool/UThreadPool.cpp:244–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242
243
244CVoid UThreadPool::monitor() {
245 while (config_.monitor_enable_) {
246 while (config_.monitor_enable_ && !is_init_) {
247 // 如果没有init,则一直处于空跑状态
248 CGRAPH_SLEEP_SECOND(1)
249 }
250
251 auto span = config_.monitor_span_;
252 while (config_.monitor_enable_ && is_init_ && span--) {
253 CGRAPH_SLEEP_SECOND(1) // 保证可以快速退出
254 }
255
256 // 如果 primary线程都在执行,则表示忙碌
257 const bool busy = !primary_threads_.empty() && std::all_of(primary_threads_.begin(), primary_threads_.end(),
258 [](UThreadPrimaryPtr ptr) { return ptr && ptr->is_running_; });
259
260 // 如果忙碌或者priority_task_queue_中有任务,则需要添加 secondary线程
261 if (busy || !priority_task_queue_.empty()) {
262 createSecondaryThread(1);
263 }
264
265 CGRAPH_LOCK_GUARD lock(st_mutex_);
266 // 判断 secondary 线程是否需要退出
267 for (auto iter = secondary_threads_.begin(); iter != secondary_threads_.end(); ) {
268 (*iter)->freeze() ? secondary_threads_.erase(iter++) : iter++;
269 }
270 }
271}
272
273
274CSize UThreadPool::wakeupAllThread() const {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected