diff --git a/src/bees-hash.cc b/src/bees-hash.cc index cb0b2b5..d0afe81 100644 --- a/src/bees-hash.cc +++ b/src/bees-hash.cc @@ -5,7 +5,6 @@ #include "crucible/string.h" #include -#include #include @@ -538,6 +537,8 @@ BeesHashTable::push_front_hash_addr(HashType hash, AddrType addr) return found; } +thread_local uniform_int_distribution BeesHashTable::tl_distribution(0, c_cells_per_bucket - 1); + /// Insert a hash entry at some unspecified point in the list. /// If entry is already present in list, returns true and does not /// modify list. If entry is not present in list, returns false and @@ -555,9 +556,7 @@ BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr) Cell *ip = find(er.first, er.second, mv); bool found = (ip < er.second); - thread_local default_random_engine generator; - thread_local uniform_int_distribution distribution(0, c_cells_per_bucket - 1); - auto pos = distribution(generator); + const auto pos = tl_distribution(bees_generator); int case_cond = 0; #if 0 diff --git a/src/bees.cc b/src/bees.cc index 9041f71..645c744 100644 --- a/src/bees.cc +++ b/src/bees.cc @@ -268,6 +268,13 @@ bees_unreadahead(int const fd, off_t offset, size_t size) BEESCOUNTADD(readahead_unread_ms, unreadahead_timer.age() * 1000); } +thread_local random_device bees_random_device; +thread_local uniform_int_distribution bees_random_seed_dist( + numeric_limits::min(), + numeric_limits::max() +); +thread_local default_random_engine bees_generator(bees_random_seed_dist(bees_random_device)); + BeesStringFile::BeesStringFile(Fd dir_fd, string name, size_t limit) : m_dir_fd(dir_fd), m_name(name), diff --git a/src/bees.h b/src/bees.h index 40089ad..97c056b 100644 --- a/src/bees.h +++ b/src/bees.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -496,6 +497,8 @@ private: BeesHashTable(const BeesHashTable &) = delete; BeesHashTable &operator=(const BeesHashTable &) = delete; + + static thread_local uniform_int_distribution tl_distribution; }; ostream &operator<<(ostream &os, const BeesHashTable::Cell &bhte); @@ -881,6 +884,7 @@ public: extern int bees_log_level; extern const char *BEES_USAGE; extern const char *BEES_VERSION; +extern thread_local default_random_engine bees_generator; string pretty(double d); void bees_sync(int fd); void bees_readahead(int fd, off_t offset, size_t size);