mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
refactor: Use move semantics in CCheckQueue::Loop
Co-authored-by: Martin Leitner-Ankerl <martin.ankerl@gmail.com>
This commit is contained in:
parent
9a0b524139
commit
d8427cc28e
3 changed files with 3 additions and 18 deletions
|
@ -29,7 +29,6 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
|
||||||
|
|
||||||
struct PrevectorJob {
|
struct PrevectorJob {
|
||||||
prevector<PREVECTOR_SIZE, uint8_t> p;
|
prevector<PREVECTOR_SIZE, uint8_t> p;
|
||||||
PrevectorJob() = default;
|
|
||||||
explicit PrevectorJob(FastRandomContext& insecure_rand){
|
explicit PrevectorJob(FastRandomContext& insecure_rand){
|
||||||
p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
|
p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
|
||||||
}
|
}
|
||||||
|
@ -37,10 +36,6 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void swap(PrevectorJob& x) noexcept
|
|
||||||
{
|
|
||||||
p.swap(x.p);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE};
|
CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE};
|
||||||
// The main thread should be counted to prevent thread oversubscription, and
|
// The main thread should be counted to prevent thread oversubscription, and
|
||||||
|
|
|
@ -112,13 +112,9 @@ private:
|
||||||
// * Try to account for idle jobs which will instantly start helping.
|
// * Try to account for idle jobs which will instantly start helping.
|
||||||
// * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
|
// * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
|
||||||
nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
|
nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
|
||||||
vChecks.resize(nNow);
|
auto start_it = queue.end() - nNow;
|
||||||
for (unsigned int i = 0; i < nNow; i++) {
|
vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
|
||||||
// We want the lock on the m_mutex to be as short as possible, so swap jobs from the global
|
queue.erase(start_it, queue.end());
|
||||||
// queue to the local batch vector instead of copying.
|
|
||||||
vChecks[i].swap(queue.back());
|
|
||||||
queue.pop_back();
|
|
||||||
}
|
|
||||||
// Check whether we need to do work at all
|
// Check whether we need to do work at all
|
||||||
fOk = fAllOk;
|
fOk = fAllOk;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ namespace {
|
||||||
struct DumbCheck {
|
struct DumbCheck {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
DumbCheck() = default;
|
|
||||||
|
|
||||||
explicit DumbCheck(const bool _result) : result(_result)
|
explicit DumbCheck(const bool _result) : result(_result)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -25,10 +23,6 @@ struct DumbCheck {
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(DumbCheck& x) noexcept
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue