NFC: move get_entropy64 from mem to ds

These functions depend only on the PAL and so can live lower down the
stack.
This commit is contained in:
Nathaniel Wesley Filardo
2022-12-09 12:55:29 +00:00
committed by Nathaniel Filardo
parent 20c9e57668
commit 7c35c42eae
3 changed files with 28 additions and 21 deletions

View File

@@ -6,6 +6,7 @@
#include "../pal/pal.h"
#include "aba.h"
#include "allocconfig.h"
#include "entropy.h"
#include "flaglock.h"
#include "mpmcstack.h"
#include "singleton.h"

26
src/snmalloc/ds/entropy.h Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
#ifndef SNMALLOC_PLATFORM_HAS_GETENTROPY
# include <random>
#endif
namespace snmalloc
{
template<typename PAL>
std::enable_if_t<pal_supports<Entropy, PAL>, uint64_t> get_entropy64()
{
return PAL::get_entropy64();
}
template<typename PAL>
std::enable_if_t<!pal_supports<Entropy, PAL>, uint64_t> get_entropy64()
{
#ifdef SNMALLOC_PLATFORM_HAS_GETENTROPY
return DefaultPal::get_entropy64();
#else
std::random_device rd;
uint64_t a = rd();
return (a << 32) ^ rd();
#endif
}
} // namespace snmalloc

View File

@@ -1,33 +1,13 @@
#pragma once
#include "../ds/ds.h"
#include "../pal/pal.h"
#include <cstdint>
#include <type_traits>
#ifndef SNMALLOC_PLATFORM_HAS_GETENTROPY
# include <random>
#endif
namespace snmalloc
{
template<typename PAL>
std::enable_if_t<pal_supports<Entropy, PAL>, uint64_t> get_entropy64()
{
return PAL::get_entropy64();
}
template<typename PAL>
std::enable_if_t<!pal_supports<Entropy, PAL>, uint64_t> get_entropy64()
{
#ifdef SNMALLOC_PLATFORM_HAS_GETENTROPY
return DefaultPal::get_entropy64();
#else
std::random_device rd;
uint64_t a = rd();
return (a << 32) ^ rd();
#endif
}
struct FreeListKey
{
address_t key1;