#pragma once #include "Allocator.h" #include "Base.h" // #include "Arena.h" struct Arena; // #TEMP - Base_Thread_Context and Arena rely on each other, so I have to figure out how to make this less messy (maybe with meta-generated forward declares?) // See Context_Base in jai, and TCTX in raddebugger: struct Thread_Context { Arena* temp; // Used for temporary allocations. Arena* arena; // general purpose local arena Allocator allocator; u16 GPAllocator_alignment = 16; // Logger logger; // Stack_Trace* stack_trace; // #TODO: other debug information s64 thread_idx; string thread_name; }; Thread_Context* get_thread_context(); // maybe should append line number to guard? // This is stupid, and maybe should be something generated by a metaprogram? #define push_allocator(x) Push_Allocator Concat(_push_alloc_guard_, __LINE__)(x) struct Push_Allocator { Thread_Context* context; Allocator old_allocator; Push_Allocator (Allocator new_allocator) { context = get_thread_context(); old_allocator = context->allocator; context->allocator = new_allocator; } ~Push_Allocator () { context->allocator = old_allocator; } }; // Thread-local allocators: PROTOTYPING_API Allocator get_temp_allocator(); PROTOTYPING_API Allocator get_context_allocator(); PROTOTYPING_API void reset_temp_allocator(); PROTOTYPING_API void free_temp_allocator();