From 7c35c42eae5a608a7fcb9c85beeafb49a5c83eb1 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Fri, 9 Dec 2022 12:55:29 +0000 Subject: [PATCH] NFC: move get_entropy64 from mem to ds These functions depend only on the PAL and so can live lower down the stack. --- src/snmalloc/ds/ds.h | 1 + src/snmalloc/ds/entropy.h | 26 ++++++++++++++++++++++++++ src/snmalloc/mem/entropy.h | 22 +--------------------- 3 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 src/snmalloc/ds/entropy.h diff --git a/src/snmalloc/ds/ds.h b/src/snmalloc/ds/ds.h index 432277d..37ebad0 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 0000000..431495e --- /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 1b59094..2e63b68 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;