mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
test/checkqueue_tests: thread safety annotations
This commit is contained in:
parent
479c5846f7
commit
a788789948
1 changed files with 14 additions and 9 deletions
|
@ -3,6 +3,7 @@
|
|||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <checkqueue.h>
|
||||
#include <sync.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/memory.h>
|
||||
#include <util/system.h>
|
||||
|
@ -57,14 +58,14 @@ struct FailingCheck {
|
|||
};
|
||||
|
||||
struct UniqueCheck {
|
||||
static std::mutex m;
|
||||
static std::unordered_multiset<size_t> results;
|
||||
static Mutex m;
|
||||
static std::unordered_multiset<size_t> results GUARDED_BY(m);
|
||||
size_t check_id;
|
||||
UniqueCheck(size_t check_id_in) : check_id(check_id_in){};
|
||||
UniqueCheck() : check_id(0){};
|
||||
bool operator()()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m);
|
||||
LOCK(m);
|
||||
results.insert(check_id);
|
||||
return true;
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ struct FrozenCleanupCheck {
|
|||
std::mutex FrozenCleanupCheck::m{};
|
||||
std::atomic<uint64_t> FrozenCleanupCheck::nFrozen{0};
|
||||
std::condition_variable FrozenCleanupCheck::cv{};
|
||||
std::mutex UniqueCheck::m;
|
||||
Mutex UniqueCheck::m;
|
||||
std::unordered_multiset<size_t> UniqueCheck::results;
|
||||
std::atomic<size_t> FakeCheckCheckCompletion::n_calls{0};
|
||||
std::atomic<size_t> MemoryCheck::fake_allocated_memory{0};
|
||||
|
@ -290,11 +291,15 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
|
|||
control.Add(vChecks);
|
||||
}
|
||||
}
|
||||
bool r = true;
|
||||
BOOST_REQUIRE_EQUAL(UniqueCheck::results.size(), COUNT);
|
||||
for (size_t i = 0; i < COUNT; ++i)
|
||||
r = r && UniqueCheck::results.count(i) == 1;
|
||||
BOOST_REQUIRE(r);
|
||||
{
|
||||
LOCK(UniqueCheck::m);
|
||||
bool r = true;
|
||||
BOOST_REQUIRE_EQUAL(UniqueCheck::results.size(), COUNT);
|
||||
for (size_t i = 0; i < COUNT; ++i) {
|
||||
r = r && UniqueCheck::results.count(i) == 1;
|
||||
}
|
||||
BOOST_REQUIRE(r);
|
||||
}
|
||||
tg.interrupt_all();
|
||||
tg.join_all();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue