| 224 | |
| 225 | |
| 226 | CStatus UThreadPool::createSecondaryThread(const CInt size) { |
| 227 | CGRAPH_FUNCTION_BEGIN |
| 228 | |
| 229 | const int leftSize = static_cast<int>(config_.max_thread_size_ - config_.default_thread_size_ - secondary_threads_.size()); |
| 230 | const int realSize = std::min(size, leftSize); // 使用 realSize 来确保所有的线程数量之和,不会超过设定max值 |
| 231 | |
| 232 | CGRAPH_LOCK_GUARD lock(st_mutex_); |
| 233 | for (int i = 0; i < realSize; i++) { |
| 234 | auto ptr = CGRAPH_MAKE_UNIQUE_COBJECT(UThreadSecondary) |
| 235 | ptr->setThreadPoolInfo(&task_queue_, &priority_task_queue_, &config_); |
| 236 | status += ptr->init(); |
| 237 | secondary_threads_.emplace_back(std::move(ptr)); |
| 238 | } |
| 239 | |
| 240 | CGRAPH_FUNCTION_END |
| 241 | } |
| 242 | |
| 243 | |
| 244 | CVoid UThreadPool::monitor() { |