Add a fast path to ensure_init (#605)

This commit is contained in:
Matthew Parkinson
2023-03-24 09:15:45 +00:00
committed by GitHub
parent 798f2fa367
commit 0620825df7

View File

@@ -93,21 +93,9 @@ namespace snmalloc
SNMALLOC_REQUIRE_CONSTINIT
inline static FlagWord initialisation_lock{};
public:
/**
* Provides the state to create new allocators.
*/
static GlobalPoolState& pool()
{
return alloc_pool;
}
static constexpr Flags Options{};
// Performs initialisation for this configuration
// of allocators. Needs to be idempotent,
// and concurrency safe.
static void ensure_init()
// of allocators.
SNMALLOC_SLOW_PATH static void ensure_init_slow()
{
FlagLock lock{initialisation_lock};
# ifdef SNMALLOC_TRACING
@@ -135,7 +123,29 @@ namespace snmalloc
Authmap::init();
}
initialised = true;
initialised.store(true, std::memory_order_release);
}
public:
/**
* Provides the state to create new allocators.
*/
static GlobalPoolState& pool()
{
return alloc_pool;
}
static constexpr Flags Options{};
// Performs initialisation for this configuration
// of allocators. Needs to be idempotent,
// and concurrency safe.
SNMALLOC_FAST_PATH static void ensure_init()
{
if (SNMALLOC_LIKELY(initialised.load(std::memory_order_acquire)))
return;
ensure_init_slow();
}
static bool is_initialised()