diff --git a/src/common.cpp b/src/common.cpp index 199a263a1..988a992d0 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -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" diff --git a/src/main.cpp b/src/main.cpp index 7ac78241e..c07d2c400 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/src/parser.cpp b/src/parser.cpp index 046469c16..c6f35d326 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -64,11 +64,9 @@ gb_global std::atomic 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; diff --git a/src/parser.hpp b/src/parser.hpp index b492cfa85..d81194831 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -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); diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp index 083cd6697..264136881 100644 --- a/src/ptr_map.cpp +++ b/src/ptr_map.cpp @@ -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); diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 07ab3d323..276e93dff 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -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); diff --git a/src/threading.cpp b/src/threading.cpp index aca77cd8f..78943150e 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -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; diff --git a/src/types.cpp b/src/types.cpp index d33c36e94..fa7c1d7f7 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -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; } }