From f3a9d3a682dd39717b67d7251431f81667c3d2ab Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 2 May 2021 10:50:27 +0100 Subject: [PATCH] c++20 (timid) introduction of constinit proposal. --- src/ds/defines.h | 8 ++++++++ src/pal/pal_bsd_aligned.h | 2 +- src/pal/pal_windows.h | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ds/defines.h b/src/ds/defines.h index e67e36d..a240739 100644 --- a/src/ds/defines.h +++ b/src/ds/defines.h @@ -20,6 +20,14 @@ # define SNMALLOC_COLD __attribute__((cold)) #endif +#if defined(__cpp_constinit) && __cpp_constinit >= 201907 +# define SNMALLOC_CONSTINIT_FN constinit +# define SNMALLOC_CONSTINIT_STATIC constinit const +#else +# define SNMALLOC_CONSTINIT_FN constexpr +# define SNMALLOC_CONSTINIT_STATIC constexpr +#endif + #if !defined(__clang__) && defined(__GNUC__) # define GCC_NOT_CLANG #endif diff --git a/src/pal/pal_bsd_aligned.h b/src/pal/pal_bsd_aligned.h index c93eb4c..bac3e82 100644 --- a/src/pal/pal_bsd_aligned.h +++ b/src/pal/pal_bsd_aligned.h @@ -23,7 +23,7 @@ namespace snmalloc static constexpr uint64_t pal_features = AlignedAllocation | PALBSD::pal_features; - static constexpr size_t minimum_alloc_size = 4096; + static SNMALLOC_CONSTINIT_STATIC size_t minimum_alloc_size = 4096; /** * Reserve memory at a specific alignment. diff --git a/src/pal/pal_windows.h b/src/pal/pal_windows.h index 3c95525..847a04b 100644 --- a/src/pal/pal_windows.h +++ b/src/pal/pal_windows.h @@ -58,7 +58,7 @@ namespace snmalloc # endif ; - static constexpr size_t minimum_alloc_size = 0x10000; + static SNMALLOC_CONSTINIT_STATIC size_t minimum_alloc_size = 0x10000; static constexpr size_t page_size = 0x1000;