* 从其他线程窃取一个任务 * @param task * @return */
| 185 | * @return |
| 186 | */ |
| 187 | CBool stealTask(UTaskRef task) const { |
| 188 | if (unlikely(pool_threads_->size() < static_cast<CSize>(config_->default_thread_size_))) { |
| 189 | /** |
| 190 | * 线程池还未初始化完毕的时候,无法进行steal。 |
| 191 | * 确保程序安全运行。 |
| 192 | */ |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | CBool result = false; |
| 197 | for (const auto target : steal_targets_) { |
| 198 | /** |
| 199 | * 从线程中周围的thread中,窃取任务。 |
| 200 | * 如果成功,则返回true,并且执行任务。 |
| 201 | */ |
| 202 | if (likely((*pool_threads_)[target]) |
| 203 | && ((*pool_threads_)[target])->wsq_.trySteal(task)) { |
| 204 | result = true; |
| 205 | break; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return result; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /** |
no outgoing calls
no test coverage detected