refactor: replace Boost shared_mutex with std shared_mutex in cuckoocache tests

Co-authored-by: MarcoFalke falke.marco@gmail.com
Co-authored-by: sinetek pitwuu@gmail.com
This commit is contained in:
fanquake 2021-02-02 09:41:31 +08:00
parent f72d80b07a
commit 8e55981ef8
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -1,15 +1,18 @@
// Copyright (c) 2012-2020 The Bitcoin Core developers // Copyright (c) 2012-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <boost/test/unit_test.hpp>
#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <cuckoocache.h> #include <cuckoocache.h>
#include <deque>
#include <random.h> #include <random.h>
#include <script/sigcache.h> #include <script/sigcache.h>
#include <test/util/setup_common.h> #include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <deque>
#include <mutex>
#include <shared_mutex>
#include <thread> #include <thread>
#include <vector>
/** Test Suite for CuckooCache /** Test Suite for CuckooCache
* *
@ -201,11 +204,11 @@ static void test_cache_erase_parallel(size_t megabytes)
* "future proofed". * "future proofed".
*/ */
std::vector<uint256> hashes_insert_copy = hashes; std::vector<uint256> hashes_insert_copy = hashes;
boost::shared_mutex mtx; std::shared_mutex mtx;
{ {
/** Grab lock to make sure we release inserts */ /** Grab lock to make sure we release inserts */
boost::unique_lock<boost::shared_mutex> l(mtx); std::unique_lock<std::shared_mutex> l(mtx);
/** Insert the first half */ /** Insert the first half */
for (uint32_t i = 0; i < (n_insert / 2); ++i) for (uint32_t i = 0; i < (n_insert / 2); ++i)
set.insert(hashes_insert_copy[i]); set.insert(hashes_insert_copy[i]);
@ -219,7 +222,7 @@ static void test_cache_erase_parallel(size_t megabytes)
/** 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); std::shared_lock<std::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);
@ -234,7 +237,7 @@ static void test_cache_erase_parallel(size_t megabytes)
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); std::unique_lock<std::shared_mutex> l(mtx);
/** Insert the second half */ /** Insert the second half */
for (uint32_t i = (n_insert / 2); i < n_insert; ++i) for (uint32_t i = (n_insert / 2); i < n_insert; ++i)
set.insert(hashes_insert_copy[i]); set.insert(hashes_insert_copy[i]);