diff --git a/src/snmalloc/ds/ds.h b/src/snmalloc/ds/ds.h index 432277dc..37ebad07 100644 --- a/src/snmalloc/ds/ds.h +++ b/src/snmalloc/ds/ds.h @@ -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" diff --git a/src/snmalloc/ds/entropy.h b/src/snmalloc/ds/entropy.h new file mode 100644 index 00000000..431495e2 --- /dev/null +++ b/src/snmalloc/ds/entropy.h @@ -0,0 +1,26 @@ +#pragma once + +#ifndef SNMALLOC_PLATFORM_HAS_GETENTROPY +# include +#endif + +namespace snmalloc +{ + template + std::enable_if_t, uint64_t> get_entropy64() + { + return PAL::get_entropy64(); + } + + template + std::enable_if_t, 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 diff --git a/src/snmalloc/mem/entropy.h b/src/snmalloc/mem/entropy.h index 1b590942..2e63b68b 100644 --- a/src/snmalloc/mem/entropy.h +++ b/src/snmalloc/mem/entropy.h @@ -1,33 +1,13 @@ #pragma once +#include "../ds/ds.h" #include "../pal/pal.h" #include #include -#ifndef SNMALLOC_PLATFORM_HAS_GETENTROPY -# include -#endif namespace snmalloc { - template - std::enable_if_t, uint64_t> get_entropy64() - { - return PAL::get_entropy64(); - } - - template - std::enable_if_t, 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;