Changeset View
Changeset View
Standalone View
Standalone View
src/checkqueue.h
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | bool Loop(bool fMaster = false) { | ||||
// Decide how many work units to process now. | // Decide how many work units to process now. | ||||
// * Do not try to do everything at once, but aim for | // * Do not try to do everything at once, but aim for | ||||
// increasingly smaller batches so all workers finish | // increasingly smaller batches so all workers finish | ||||
// approximately simultaneously. | // approximately simultaneously. | ||||
// * Try to account for idle jobs which will instantly start | // * Try to account for idle jobs which will instantly start | ||||
// helping. | // helping. | ||||
// * Don't do batches smaller than 1 (duh), or larger than | // * Don't do batches smaller than 1 (duh), or larger than | ||||
// nBatchSize. | // nBatchSize. | ||||
nNow = std::max(1U, std::min(nBatchSize, | nNow = std::max( | ||||
(unsigned int)queue.size() / | 1U, std::min(nBatchSize, (unsigned int)queue.size() / | ||||
(nTotal + nIdle + 1))); | (nTotal + nIdle + 1))); | ||||
vChecks.resize(nNow); | vChecks.resize(nNow); | ||||
for (unsigned int i = 0; i < nNow; i++) { | for (unsigned int i = 0; i < nNow; i++) { | ||||
// We want the lock on the mutex to be as short as possible, | // We want the lock on the mutex to be as short as possible, | ||||
// so swap jobs from the global queue to the local batch | // so swap jobs from the global queue to the local batch | ||||
// vector instead of copying. | // vector instead of copying. | ||||
vChecks[i].swap(queue.back()); | vChecks[i].swap(queue.back()); | ||||
queue.pop_back(); | queue.pop_back(); | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |