General improves to alloc_ast_node and other unnecessary checks

This commit is contained in:
gingerBill
2023-01-03 14:45:09 +00:00
parent 69934c3b0b
commit 0fb3032b73
8 changed files with 16 additions and 16 deletions
+1 -1
View File
@@ -43,9 +43,9 @@ gb_internal void debugf(char const *fmt, ...);
#error Odin on Windows requires a 64-bit build-system. The 'Developer Command Prompt' for VS still defaults to 32-bit shell. The 64-bit shell can be found under the name 'x64 Native Tools Command Prompt' for VS. For more information, please see https://odin-lang.org/docs/install/#for-windows
#endif
#include "threading.cpp"
#include "unicode.cpp"
#include "array.cpp"
#include "threading.cpp"
#include "queue.cpp"
#include "common_memory.cpp"
#include "string.cpp"
+2 -2
View File
@@ -13,11 +13,11 @@
#endif
#include "exact_value.cpp"
#include "build_settings.cpp"
gb_global ThreadPool global_thread_pool;
gb_internal void init_global_thread_pool(void) {
isize thread_count = gb_max(build_context.thread_count, 1);
thread_pool_init(&global_thread_pool, permanent_allocator(), thread_count, "ThreadPoolWorker");
isize worker_count = thread_count-1;
thread_pool_init(&global_thread_pool, permanent_allocator(), worker_count, "ThreadPoolWorker");
}
gb_internal bool thread_pool_add_task(WorkerTaskProc *proc, void *data) {
return thread_pool_add_task(&global_thread_pool, proc, data);
+1 -3
View File
@@ -64,11 +64,9 @@ gb_global std::atomic<isize> global_total_node_memory_allocated;
// NOTE(bill): And this below is why is I/we need a new language! Discriminated unions are a pain in C/C++
gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) {
gbAllocator a = ast_allocator(f);
isize size = ast_node_size(kind);
Ast *node = cast(Ast *)gb_alloc(a, size);
Ast *node = cast(Ast *)arena_alloc(&global_thread_local_ast_arena, size, 16);
node->kind = kind;
node->file_id = f ? f->id : 0;
+2 -3
View File
@@ -821,9 +821,8 @@ gb_internal gb_inline bool is_ast_when_stmt(Ast *node) {
gb_global gb_thread_local Arena global_thread_local_ast_arena = {};
gb_internal gbAllocator ast_allocator(AstFile *f) {
Arena *arena = &global_thread_local_ast_arena;
return arena_allocator(arena);
gb_internal gb_inline gbAllocator ast_allocator(AstFile *f) {
return arena_allocator(&global_thread_local_ast_arena);
}
gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind);
+4 -2
View File
@@ -27,6 +27,7 @@ struct PtrMap {
gb_internal gb_inline u32 ptr_map_hash_key(uintptr key) {
u32 res;
#if defined(GB_ARCH_64_BIT)
key = (~key) + (key << 21);
key = key ^ (key >> 24);
@@ -34,12 +35,13 @@ gb_internal gb_inline u32 ptr_map_hash_key(uintptr key) {
key = key ^ (key >> 14);
key = (key + (key << 2)) + (key << 4);
key = key ^ (key << 28);
return cast(u32)key;
res = cast(u32)key;
#elif defined(GB_ARCH_32_BIT)
u32 state = ((u32)key) * 747796405u + 2891336453u;
u32 word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
return (word >> 22u) ^ word;
res = (word >> 22u) ^ word;
#endif
return res ^ (res == MAP_SENTINEL);
}
gb_internal gb_inline u32 ptr_map_hash_key(void const *key) {
return ptr_map_hash_key((uintptr)key);
+3 -3
View File
@@ -5,7 +5,7 @@ struct ThreadPool;
gb_thread_local Thread *current_thread;
gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name);
gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize worker_count, char const *worker_name);
gb_internal void thread_pool_destroy(ThreadPool *pool);
gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data);
gb_internal void thread_pool_wait(ThreadPool *pool);
@@ -25,9 +25,9 @@ gb_internal isize current_thread_index(void) {
return current_thread ? current_thread->idx : 0;
}
gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name) {
gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize worker_count, char const *worker_name) {
pool->allocator = a;
slice_init(&pool->threads, a, thread_count + 1);
slice_init(&pool->threads, a, worker_count + 1);
// NOTE: this needs to be initialized before any thread starts
pool->running.store(true, std::memory_order_seq_cst);
+1
View File
@@ -398,6 +398,7 @@ gb_internal void thread_init(ThreadPool *pool, Thread *t, isize idx) {
t->idx = idx;
}
gb_internal void thread_init_and_start(ThreadPool *pool, Thread *t, isize idx) {
thread_init(pool, t, idx);
isize stack_size = 0;
+2 -2
View File
@@ -2535,13 +2535,13 @@ gb_internal bool are_types_identical_internal(Type *x, Type *y, bool check_tuple
if (x->kind == Type_Named) {
Entity *e = x->Named.type_name;
if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) {
if (e->TypeName.is_type_alias) {
x = x->Named.base;
}
}
if (y->kind == Type_Named) {
Entity *e = y->Named.type_name;
if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) {
if (e->TypeName.is_type_alias) {
y = y->Named.base;
}
}