Musa-Cpp-Lib-V2/lib/Base/Base_Thread_Context.h

72 lines
2.0 KiB
C

#pragma once
#include "Base.h"
#include "General_Purpose_Allocator.h"
// #include "Arena.h"
// #include "Logger.h"
#include "MString.h"
// #include "Threads.h"
// #include "Expandable_Arena.h"
struct Thread_Context {
// ExpandableArena* temp; // Used for temporary allocations, scratch space.
// ExpandableArena* arena; // general purpose local arena
Allocator allocator;
s32 thread_idx;
// u16 _padding0;
u16 GPAllocator_alignment = 16;
// Logger logger = {nullptr, nullptr};
// String_Builder* log_builder;
// Stack_Trace* stack_trace;
// Array<Thread*> child_threads; // maybe should be linked-list?
Thread_Context* parent_thread_context = nullptr; // so we can remove from above array
string thread_name;
Allocator error_allocator = GPAllocator();
// Error* first_error = nullptr;
// Error* current_error = nullptr;
// Arena* error_arena;
// Graphics stuff:
// Graphics* graphics;
void* userdata; // for appending other arenas, etc.
};
// C_LINKAGE thread_static TCTX* tctx_thread_local;
thread_static Thread_Context* thread_local_context;
// #TODO #NewContext void create_thread_context (Thread_Context** context, string thread_name, bool is_main_thread);
// Thread-context #Errors:
internal void Bootstrap_Main_Thread_Context ();
struct Push_Allocator {
Thread_Context* context;
Allocator old_allocator;
Push_Allocator (Allocator new_allocator) {
context = thread_context();
old_allocator = context->allocator;
context->allocator = new_allocator;
}
~Push_Allocator () {
context->allocator = old_allocator;
}
};
// #TODO: Turn this into a macro that also provides the
// file, line number to the print.
void print_context_allocator ();
// void print_context_allocator () {
// Assert(thread_context()->allocator.proc);
// char* result = (char*)thread_context()->allocator.proc(Allocator_Mode::DETAILS, 0, 0, nullptr, thread_context()->allocator.data);
// log_none("Current allocator details: %s", result);
// }