Removing static mutex for the random pool and replacing the random pool with a thread_local version so it is thread safe. (#3408)
This commit is contained in:
parent
9278124907
commit
4d1119c45f
3 changed files with 2 additions and 9 deletions
|
@ -2,31 +2,26 @@
|
|||
|
||||
#include <crypto/cryptopp/osrng.h>
|
||||
|
||||
std::mutex nano::random_pool::mutex;
|
||||
|
||||
void nano::random_pool::generate_block (unsigned char * output, size_t size)
|
||||
{
|
||||
auto & pool = get_pool ();
|
||||
std::lock_guard guard (mutex);
|
||||
pool.GenerateBlock (output, size);
|
||||
}
|
||||
|
||||
unsigned nano::random_pool::generate_word32 (unsigned min, unsigned max)
|
||||
{
|
||||
auto & pool = get_pool ();
|
||||
std::lock_guard guard (mutex);
|
||||
return pool.GenerateWord32 (min, max);
|
||||
}
|
||||
|
||||
unsigned char nano::random_pool::generate_byte ()
|
||||
{
|
||||
auto & pool = get_pool ();
|
||||
std::lock_guard guard (mutex);
|
||||
return pool.GenerateByte ();
|
||||
}
|
||||
|
||||
CryptoPP::AutoSeededRandomPool & nano::random_pool::get_pool ()
|
||||
{
|
||||
static CryptoPP::AutoSeededRandomPool pool;
|
||||
static thread_local CryptoPP::AutoSeededRandomPool pool;
|
||||
return pool;
|
||||
}
|
||||
|
|
|
@ -22,10 +22,9 @@ public:
|
|||
random_pool & operator= (random_pool const &) = delete;
|
||||
|
||||
private:
|
||||
static std::mutex mutex;
|
||||
static CryptoPP::AutoSeededRandomPool & get_pool ();
|
||||
|
||||
template <class Iter>
|
||||
friend void random_pool_shuffle (Iter begin, Iter end);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace nano
|
|||
template <class Iter>
|
||||
void random_pool_shuffle (Iter begin, Iter end)
|
||||
{
|
||||
std::lock_guard guard (random_pool::mutex);
|
||||
random_pool::get_pool ().Shuffle (begin, end);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue