Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing static mutex for the random pool #3408

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions nano/crypto_lib/random_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 1 addition & 2 deletions nano/crypto_lib/random_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ class random_pool
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);
};
}
}
1 change: 0 additions & 1 deletion nano/crypto_lib/random_pool_shuffle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}