mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
partial #21064: use std::shared_mutex
This commit is contained in:
parent
c81f430289
commit
948bce7fb4
@ -12,7 +12,11 @@
|
||||
#include <util/system.h>
|
||||
|
||||
#include <cuckoocache.h>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
/**
|
||||
@ -27,7 +31,7 @@ private:
|
||||
uint256 nonce;
|
||||
typedef CuckooCache::cache<uint256, SignatureCacheHasher> map_type;
|
||||
map_type setValid;
|
||||
boost::shared_mutex cs_sigcache;
|
||||
std::shared_mutex cs_sigcache;
|
||||
|
||||
public:
|
||||
CSignatureCache()
|
||||
@ -44,13 +48,13 @@ public:
|
||||
bool
|
||||
Get(const uint256& entry, const bool erase)
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lock(cs_sigcache);
|
||||
std::shared_lock<std::shared_mutex> lock(cs_sigcache);
|
||||
return setValid.contains(entry, erase);
|
||||
}
|
||||
|
||||
void Set(uint256& entry)
|
||||
{
|
||||
boost::unique_lock<boost::shared_mutex> lock(cs_sigcache);
|
||||
std::unique_lock<std::shared_mutex> lock(cs_sigcache);
|
||||
setValid.insert(entry);
|
||||
}
|
||||
uint32_t setup_bytes(size_t n)
|
||||
|
@ -1,13 +1,18 @@
|
||||
// Copyright (c) 2012-2016 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <cuckoocache.h>
|
||||
#include <script/sigcache.h>
|
||||
#include <test/test_dash.h>
|
||||
#include <random.h>
|
||||
#include <thread>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
/** Test Suite for CuckooCache
|
||||
*
|
||||
@ -199,11 +204,11 @@ static void test_cache_erase_parallel(size_t megabytes)
|
||||
* "future proofed".
|
||||
*/
|
||||
std::vector<uint256> hashes_insert_copy = hashes;
|
||||
boost::shared_mutex mtx;
|
||||
std::shared_mutex mtx;
|
||||
|
||||
{
|
||||
/** 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 */
|
||||
for (uint32_t i = 0; i < (n_insert / 2); ++i)
|
||||
set.insert(hashes_insert_copy[i]);
|
||||
@ -217,7 +222,7 @@ static void test_cache_erase_parallel(size_t megabytes)
|
||||
/** Each thread is emplaced with x copy-by-value
|
||||
*/
|
||||
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 start = ntodo*x;
|
||||
size_t end = ntodo*(x+1);
|
||||
@ -230,7 +235,7 @@ static void test_cache_erase_parallel(size_t megabytes)
|
||||
for (std::thread& t : threads)
|
||||
t.join();
|
||||
/** 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 */
|
||||
for (uint32_t i = (n_insert / 2); i < n_insert; ++i)
|
||||
set.insert(hashes_insert_copy[i]);
|
||||
|
Loading…
Reference in New Issue
Block a user