* @brief Compare DiffItems in list and add results to compare context. * * @param myStruct [in] A structure containing compare-related data. * @param parentdiffpos [in] Position of parent diff item * @return >= 0 number of diff items, -1 if compare was aborted */
| 456 | * @return >= 0 number of diff items, -1 if compare was aborted |
| 457 | */ |
| 458 | int DirScan_CompareItems(DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos) |
| 459 | { |
| 460 | const int compareMethod = myStruct->context->GetCompareMethod(); |
| 461 | int nworkers = 1; |
| 462 | |
| 463 | if (compareMethod == CMP_CONTENT || compareMethod == CMP_QUICK_CONTENT) |
| 464 | { |
| 465 | nworkers = myStruct->nThreadCount; |
| 466 | if (nworkers <= 0) |
| 467 | nworkers += Environment::processorCount(); |
| 468 | nworkers = std::clamp(nworkers, 1, static_cast<int>(Environment::processorCount())); |
| 469 | } |
| 470 | |
| 471 | ThreadPool threadPool(nworkers, nworkers); |
| 472 | std::vector<DiffWorkerPtr> workers; |
| 473 | NotificationQueue queue; |
| 474 | myStruct->context->m_pCompareStats->SetCompareThreadCount(nworkers); |
| 475 | workers.reserve(nworkers); |
| 476 | for (int i = 0; i < nworkers; ++i) |
| 477 | { |
| 478 | workers.emplace_back(std::make_shared<DiffWorker>(queue, myStruct->context, i)); |
| 479 | threadPool.start(*workers[i]); |
| 480 | } |
| 481 | |
| 482 | int res = CompareItems(queue, myStruct, parentdiffpos); |
| 483 | |
| 484 | myStruct->context->m_pCompareStats->SetIdleCompareThreadCount(0); |
| 485 | Thread::sleep(100); |
| 486 | queue.wakeUpAll(); |
| 487 | threadPool.joinAll(); |
| 488 | |
| 489 | return res; |
| 490 | } |
| 491 | |
| 492 | static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos) |
| 493 | { |
no test coverage detected