Changeset View
Changeset View
Standalone View
Standalone View
src/test/cuckoocache_tests.cpp
Show First 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | boost::shared_mutex mtx; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Spin up 3 threads to run contains with erase. | * Spin up 3 threads to run contains with erase. | ||||
*/ | */ | ||||
std::vector<std::thread> threads; | std::vector<std::thread> threads; | ||||
/** Erase the first quarter */ | /** Erase the first quarter */ | ||||
for (uint32_t x = 0; x < 3; ++x) | for (uint32_t x = 0; x < 3; ++x) { | ||||
/** Each thread is emplaced with x copy-by-value */ | /** Each thread is emplaced with x copy-by-value */ | ||||
threads.emplace_back([&, x] { | threads.emplace_back([&, x] { | ||||
boost::shared_lock<boost::shared_mutex> l(mtx); | boost::shared_lock<boost::shared_mutex> l(mtx); | ||||
size_t ntodo = (n_insert / 4) / 3; | size_t ntodo = (n_insert / 4) / 3; | ||||
size_t start = ntodo * x; | size_t start = ntodo * x; | ||||
size_t end = ntodo * (x + 1); | size_t end = ntodo * (x + 1); | ||||
for (uint32_t i = start; i < end; ++i) { | for (uint32_t i = start; i < end; ++i) { | ||||
set.contains(hashes[i], true); | set.contains(hashes[i], true); | ||||
} | } | ||||
}); | }); | ||||
} | |||||
/** Wait for all threads to finish */ | /** Wait for all threads to finish */ | ||||
for (std::thread &t : threads) { | for (std::thread &t : threads) { | ||||
t.join(); | t.join(); | ||||
} | } | ||||
/** Grab lock to make sure we observe erases */ | /** Grab lock to make sure we observe erases */ | ||||
boost::unique_lock<boost::shared_mutex> l(mtx); | boost::unique_lock<boost::shared_mutex> l(mtx); | ||||
/** Insert the second half */ | /** Insert the second half */ | ||||
▲ Show 20 Lines • Show All 193 Lines • Show Last 20 Lines |