make global allocator initialize automatically

This commit is contained in:
Matthew 2025-04-22 08:44:42 +10:00
parent 8a7d4b30bd
commit 986e48bce4
2 changed files with 8 additions and 2 deletions

View File

@ -4,6 +4,9 @@ FLAlloc FL_ALLOC = {0};
Allocator ALLOC = {0}; Allocator ALLOC = {0};
read_only FLNode FL_NIL_NODE = {0}; read_only FLNode FL_NIL_NODE = {0};
constexpr usize FL_GLOBAL_SIZE = MB(32);
static b32 FL_GLOBAL_INIT = false;
// ::Allocator::Util::Header:: // ::Allocator::Util::Header::
static inline usize CalcPaddingWithHeader(uintptr ptr, uintptr alignment, usize header_size) 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) 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); u32 ticket = __atomic_fetch_add(&alloc->ticket, 1, __ATOMIC_SEQ_CST);
while (ticket != alloc->next_ticket); while (ticket != alloc->next_ticket);

View File

@ -44,8 +44,6 @@ void Traverse(RBTree *tree)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
GlobalFreeListInit(MB(32));
#ifdef BUILD_TEST #ifdef BUILD_TEST
RunTests(); RunTests();