diff --git a/src/allocators.c b/src/allocators.c index 3803b8b..788e886 100644 --- a/src/allocators.c +++ b/src/allocators.c @@ -4,6 +4,9 @@ FLAlloc FL_ALLOC = {0}; Allocator ALLOC = {0}; read_only FLNode FL_NIL_NODE = {0}; +constexpr usize FL_GLOBAL_SIZE = MB(32); +static b32 FL_GLOBAL_INIT = false; + // ::Allocator::Util::Header:: static inline usize CalcPaddingWithHeader(uintptr ptr, uintptr alignment, usize header_size) @@ -375,6 +378,11 @@ static rawptr FreeListAlloc(FLAlloc *alloc, usize size) static rawptr FreeListAllocAlign(FLAlloc *alloc, usize size, usize alignment) { + if (!FL_GLOBAL_INIT) + { + GlobalFreeListInit(FL_GLOBAL_SIZE); + } + u32 ticket = __atomic_fetch_add(&alloc->ticket, 1, __ATOMIC_SEQ_CST); while (ticket != alloc->next_ticket); diff --git a/src/entry_linux.c b/src/entry_linux.c index d2ccee5..0a66e2c 100644 --- a/src/entry_linux.c +++ b/src/entry_linux.c @@ -44,8 +44,6 @@ void Traverse(RBTree *tree) int main(int argc, char **argv) { - GlobalFreeListInit(MB(32)); - #ifdef BUILD_TEST RunTests();