// See Context_Base in jai, and TCTX in raddebugger: internal void Bootstrap_Main_Thread_Context () { // Timed_Block_Print_No_Context("Bootstrap_Main_Thread_Context"); // 0. Setup general allocator GPAllocator_Initialize_Allocation_Tracker(); // 1. Setup arena table arena_table = (Arena_Table*)GPAllocator_New(sizeof(Arena_Table), 64, true); // permanent allocation. memset(arena_table, 0, sizeof(Arena_Table)); initialize_arena_table(GPAllocator()); // 2. Setup thread local context // #NewContext ExpandableArena* arena_ex = expandable_arena_new(Arena_Reserve::Size_64M, 16); thread_local_context = New(get_allocator(arena_ex)); thread_local_context->temp = expandable_arena_new(Arena_Reserve::Size_2M, 16); thread_local_context->arena = arena_ex; thread_local_context->allocator = get_allocator(arena_ex); thread_local_context->thread_idx = 0; thread_local_context->thread_name = "Main Thread"; thread_local_context->log_builder = new_string_builder(Arena_Reserve::Size_64M); default_logger_initialize(); thread_local_context->logger = {default_logger_proc, &default_logger}; } struct Push_Arena { Thread_Context* context; Allocator original_allocator; Push_Arena(ExpandableArena* arena_ex) { Assert(is_valid(arena_ex)); context = get_thread_context(); Assert(context != nullptr); original_allocator = context->allocator; context->allocator = get_allocator(arena_ex); } Push_Arena(Arena* arena) { Assert(is_valid(arena)); context = get_thread_context(); Assert(context != nullptr); original_allocator = context->allocator; context->allocator = get_allocator(arena); } ~Push_Arena() { context->allocator = original_allocator; } }; force_inline void set_thread_context (Thread_Context* new_context) { thread_local_context = new_context; } Thread_Context* get_thread_context () { return (Thread_Context*)thread_local_context; } Logger* get_context_logger () { return &get_thread_context()->logger; } force_inline Allocator get_temp_allocator () { return get_allocator(get_thread_context()->temp); } force_inline Allocator get_context_allocator() { Thread_Context* context = get_thread_context(); return context->allocator; } void temp_reset_keeping_memory() { Thread_Context* context = get_thread_context(); arena_reset(context->temp, false); } void temp_reset() { // alias: reset_temporary_storage. Thread_Context* context = get_thread_context(); arena_reset(context->temp, true); }