Skip to content

Commit

Permalink
Add a fast path to ensure_init (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 authored Mar 24, 2023
1 parent 798f2fa commit 0620825
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/snmalloc/backend/globalconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0620825

Please sign in to comment.