Skip to content

Commit

Permalink
Remove hwrand_initialized.
Browse files Browse the repository at this point in the history
 All access to hwrand is now gated by GetRNGState, which initializes the hwrand code.
  • Loading branch information
sipa committed Jan 17, 2019
1 parent 9d7032e commit 4ea8e50
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ static inline int64_t GetPerformanceCounter()
}

#if defined(__x86_64__) || defined(__amd64__) || defined(__i386__)
static std::atomic<bool> hwrand_initialized{false};
static bool rdrand_supported = false;
static constexpr uint32_t CPUID_F1_ECX_RDRAND = 0x40000000;
static void InitHardwareRand()
Expand All @@ -85,12 +84,10 @@ static void InitHardwareRand()
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx & CPUID_F1_ECX_RDRAND)) {
rdrand_supported = true;
}
hwrand_initialized.store(true);
}

static void ReportHardwareRand()
{
assert(hwrand_initialized.load(std::memory_order_relaxed));
if (rdrand_supported) {
// This must be done in a separate function, as HWRandInit() may be indirectly called
// from global constructors, before logging is initialized.
Expand All @@ -110,7 +107,6 @@ static void ReportHardwareRand() {}

static bool GetHardwareRand(unsigned char* ent32) {
#if defined(__x86_64__) || defined(__amd64__) || defined(__i386__)
assert(hwrand_initialized.load(std::memory_order_relaxed));
if (rdrand_supported) {
uint8_t ok;
// Not all assemblers support the rdrand instruction, write it in hex.
Expand Down

0 comments on commit 4ea8e50

Please sign in to comment.