refactor: Make move semantics explicit for callers

This commit is contained in:
Hennadii Stepanov 2023-03-21 13:04:01 +00:00
parent 6c2d5972f3
commit 04831fee6d
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
6 changed files with 16 additions and 15 deletions

View File

@ -60,7 +60,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
// Make insecure_rand here so that each iteration is identical. // Make insecure_rand here so that each iteration is identical.
CCheckQueueControl<PrevectorJob> control(&queue); CCheckQueueControl<PrevectorJob> control(&queue);
for (auto vChecks : vBatches) { for (auto vChecks : vBatches) {
control.Add(vChecks); control.Add(std::move(vChecks));
} }
// control waits for completion by RAII, but // control waits for completion by RAII, but
// it is done explicitly here for clarity // it is done explicitly here for clarity

View File

@ -166,7 +166,7 @@ public:
} }
//! Add a batch of checks to the queue //! Add a batch of checks to the queue
void Add(std::vector<T>& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) void Add(std::vector<T>&& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
{ {
if (vChecks.empty()) { if (vChecks.empty()) {
return; return;
@ -237,10 +237,11 @@ public:
return fRet; return fRet;
} }
void Add(std::vector<T>& vChecks) void Add(std::vector<T>&& vChecks)
{ {
if (pqueue != nullptr) if (pqueue != nullptr) {
pqueue->Add(vChecks); pqueue->Add(std::move(vChecks));
}
} }
~CCheckQueueControl() ~CCheckQueueControl()

View File

@ -191,7 +191,7 @@ static void Correct_Queue_range(std::vector<size_t> range)
while (total) { while (total) {
vChecks.resize(std::min(total, (size_t) InsecureRandRange(10))); vChecks.resize(std::min(total, (size_t) InsecureRandRange(10)));
total -= vChecks.size(); total -= vChecks.size();
control.Add(vChecks); control.Add(std::move(vChecks));
} }
BOOST_REQUIRE(control.Wait()); BOOST_REQUIRE(control.Wait());
if (FakeCheckCheckCompletion::n_calls != i) { if (FakeCheckCheckCompletion::n_calls != i) {
@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
vChecks.reserve(r); vChecks.reserve(r);
for (size_t k = 0; k < r && remaining; k++, remaining--) for (size_t k = 0; k < r && remaining; k++, remaining--)
vChecks.emplace_back(remaining == 1); vChecks.emplace_back(remaining == 1);
control.Add(vChecks); control.Add(std::move(vChecks));
} }
bool success = control.Wait(); bool success = control.Wait();
if (i > 0) { if (i > 0) {
@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
std::vector<FailingCheck> vChecks; std::vector<FailingCheck> vChecks;
vChecks.resize(100, false); vChecks.resize(100, false);
vChecks[99] = end_fails; vChecks[99] = end_fails;
control.Add(vChecks); control.Add(std::move(vChecks));
} }
bool r =control.Wait(); bool r =control.Wait();
BOOST_REQUIRE(r != end_fails); BOOST_REQUIRE(r != end_fails);
@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
std::vector<UniqueCheck> vChecks; std::vector<UniqueCheck> vChecks;
for (size_t k = 0; k < r && total; k++) for (size_t k = 0; k < r && total; k++)
vChecks.emplace_back(--total); vChecks.emplace_back(--total);
control.Add(vChecks); control.Add(std::move(vChecks));
} }
} }
{ {
@ -342,7 +342,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
// to catch any sort of deallocation failure // to catch any sort of deallocation failure
vChecks.emplace_back(total == 0 || total == i || total == i/2); vChecks.emplace_back(total == 0 || total == i || total == i/2);
} }
control.Add(vChecks); control.Add(std::move(vChecks));
} }
} }
BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U); BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U);
@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
// swaps in default initialized Checks (otherwise freezing destructor // swaps in default initialized Checks (otherwise freezing destructor
// would get called twice). // would get called twice).
vChecks[0].should_freeze = true; vChecks[0].should_freeze = true;
control.Add(vChecks); control.Add(std::move(vChecks));
bool waitResult = control.Wait(); // Hangs here bool waitResult = control.Wait(); // Hangs here
assert(waitResult); assert(waitResult);
}); });

View File

@ -48,7 +48,7 @@ FUZZ_TARGET(checkqueue)
checks_2.emplace_back(result); checks_2.emplace_back(result);
} }
if (fuzzed_data_provider.ConsumeBool()) { if (fuzzed_data_provider.ConsumeBool()) {
check_queue_1.Add(checks_1); check_queue_1.Add(std::move(checks_1));
} }
if (fuzzed_data_provider.ConsumeBool()) { if (fuzzed_data_provider.ConsumeBool()) {
(void)check_queue_1.Wait(); (void)check_queue_1.Wait();
@ -56,7 +56,7 @@ FUZZ_TARGET(checkqueue)
CCheckQueueControl<DumbCheck> check_queue_control{&check_queue_2}; CCheckQueueControl<DumbCheck> check_queue_control{&check_queue_2};
if (fuzzed_data_provider.ConsumeBool()) { if (fuzzed_data_provider.ConsumeBool()) {
check_queue_control.Add(checks_2); check_queue_control.Add(std::move(checks_2));
} }
if (fuzzed_data_provider.ConsumeBool()) { if (fuzzed_data_provider.ConsumeBool()) {
(void)check_queue_control.Wait(); (void)check_queue_control.Wait();

View File

@ -548,7 +548,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction)
for(uint32_t i = 0; i < mtx.vin.size(); i++) { for(uint32_t i = 0; i < mtx.vin.size(); i++) {
std::vector<CScriptCheck> vChecks; std::vector<CScriptCheck> vChecks;
vChecks.emplace_back(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata); vChecks.emplace_back(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata);
control.Add(vChecks); control.Add(std::move(vChecks));
} }
bool controlCheck = control.Wait(); bool controlCheck = control.Wait();

View File

@ -2324,7 +2324,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
return error("ConnectBlock(): CheckInputScripts on %s failed with %s", return error("ConnectBlock(): CheckInputScripts on %s failed with %s",
tx.GetHash().ToString(), state.ToString()); tx.GetHash().ToString(), state.ToString());
} }
control.Add(vChecks); control.Add(std::move(vChecks));
} }
CTxUndo undoDummy; CTxUndo undoDummy;