зеркало из https://github.com/microsoft/snmalloc.git
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:
Родитель
20c9e57668
Коммит
7c35c42eae
|
@ -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"
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче