Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fast path to ensure_init #605

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/snmalloc/backend/globalconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,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
Expand Down Expand Up @@ -152,7 +140,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()
Expand Down