make global allocator initialize automatically
This commit is contained in:
parent
8a7d4b30bd
commit
986e48bce4
@ -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);
|
||||||
|
|
||||||
|
|||||||
@ -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();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user