| 285 | |
| 286 | |
| 287 | static void Engine_relaunchWorkers(Engine* that, int threadCount) { |
| 288 | Engine::Internal* internal = that->internal; |
| 289 | if (threadCount == internal->threadCount) |
| 290 | return; |
| 291 | |
| 292 | if (internal->threadCount > 0) { |
| 293 | // Stop engine workers |
| 294 | for (EngineWorker& worker : internal->workers) { |
| 295 | worker.requestStop(); |
| 296 | } |
| 297 | internal->engineBarrier.wait(); |
| 298 | |
| 299 | // Join and destroy engine workers |
| 300 | for (EngineWorker& worker : internal->workers) { |
| 301 | worker.join(); |
| 302 | } |
| 303 | internal->workers.resize(0); |
| 304 | } |
| 305 | |
| 306 | // Configure engine |
| 307 | internal->threadCount = threadCount; |
| 308 | |
| 309 | // Set barrier counts |
| 310 | internal->engineBarrier.setThreads(threadCount); |
| 311 | internal->workerBarrier.setThreads(threadCount); |
| 312 | |
| 313 | if (threadCount > 0) { |
| 314 | // Create and start engine workers |
| 315 | internal->workers.resize(threadCount - 1); |
| 316 | for (int id = 1; id < threadCount; id++) { |
| 317 | EngineWorker& worker = internal->workers[id - 1]; |
| 318 | worker.id = id; |
| 319 | worker.engine = that; |
| 320 | worker.start(); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | |
| 326 | static void Engine_stepWorker(Engine* that, int threadId) { |
no test coverage detected