diff --git a/src/scratch.h b/src/scratch.h index ea8e76dd..c123c46b 100644 --- a/src/scratch.h +++ b/src/scratch.h @@ -3,7 +3,7 @@ #include "arena.h" #include "sys.h" -#include "tls.h" +#include "thread_local.h" #define SCRATCH_ARENAS_PER_THREAD 2 #define SCRATCH_ARENA_RESERVE (GIGABYTE(64)) diff --git a/src/sys_win32.c b/src/sys_win32.c index 5151acb2..bbe448b6 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -9,7 +9,7 @@ #include "log.h" #include "math.h" #include "util.h" -#include "tls.h" +#include "thread_local.h" #include "utf.h" #define UNICODE diff --git a/src/tls.c b/src/thread_local.c similarity index 77% rename from src/tls.c rename to src/thread_local.c index 01c12db7..a9815142 100644 --- a/src/tls.c +++ b/src/thread_local.c @@ -1,4 +1,4 @@ -#include "tls.h" +#include "thread_local.h" #include "sys.h" #include "arena.h" #include "atomic.h" @@ -10,22 +10,22 @@ #define MAX_THREAD_LOCAL_VARS 64 GLOBAL struct { - struct atomic_i64 tls_metas_lock_flag; - u64 tls_metas_count; - struct thread_local_var_meta tls_metas[MAX_THREAD_LOCAL_VARS]; -} L = { 0 }, DEBUG_LVAR(L_tls); + struct atomic_i64 metas_lock_flag; + u64 metas_count; + struct thread_local_var_meta metas[MAX_THREAD_LOCAL_VARS]; +} L = { 0 }, DEBUG_LVAR(L_thread_local); -INTERNAL void tls_metas_lock(void) +INTERNAL void metas_lock(void) { - while (atomic_i64_eval_compare_exchange(&L.tls_metas_lock_flag, 0, 1) == 0) { + while (atomic_i64_eval_compare_exchange(&L.metas_lock_flag, 0, 1) == 0) { /* Spinlock */ ix_pause(); } } -INTERNAL void tls_metas_unlock(void) +INTERNAL void metas_unlock(void) { - atomic_i64_eval_exchange(&L.tls_metas_lock_flag, 0); + atomic_i64_eval_exchange(&L.metas_lock_flag, 0); } struct thread_local_store thread_local_store_alloc(void) @@ -41,19 +41,19 @@ struct thread_local_store thread_local_store_alloc(void) void thread_local_store_release(struct thread_local_store *t) { __prof; - /* Release allocated tls data in reverse order */ - tls_metas_lock(); + /* Release allocated vars in reverse order */ + metas_lock(); { for (u64 i = t->allocation_order_count; i-- > 0;) { u64 id = t->allocation_order[i]; void *data = t->lookup[id]; - struct thread_local_var_meta *meta = &L.tls_metas[id]; + struct thread_local_var_meta *meta = &L.metas[id]; if (meta->release) { meta->release(data); } } } - tls_metas_unlock(); + metas_unlock(); arena_release(&t->arena); } @@ -66,21 +66,21 @@ void *_thread_local_eval(struct thread_local_var_meta *meta) u64 id_plus_one = atomic_u64_eval(&meta->id_plus_one); if (id_plus_one == 0) { __profscope(_thread_local_eval__REGISTER); - tls_metas_lock(); + metas_lock(); { id_plus_one = atomic_u64_eval(&meta->id_plus_one); /* Re-check now that locked */ if (id_plus_one == 0) { - id = L.tls_metas_count++; + id = L.metas_count++; if (id >= MAX_THREAD_LOCAL_VARS) { sys_panic_raw("Maximum number of thread local variables reached"); } atomic_u64_eval_exchange(&meta->id_plus_one, id + 1); - L.tls_metas[id] = *meta; + L.metas[id] = *meta; } else { id = id_plus_one - 1; } } - tls_metas_unlock(); + metas_unlock(); } else { id = id_plus_one - 1; } diff --git a/src/tls.h b/src/thread_local.h similarity index 96% rename from src/tls.h rename to src/thread_local.h index 8e0b660e..5219bba9 100644 --- a/src/tls.h +++ b/src/thread_local.h @@ -1,5 +1,5 @@ -#ifndef TLS_H -#define TLS_H +#ifndef THREAD_LOCAL +#define THREAD_LOCAL /* ========================== * * Thread local store @@ -20,10 +20,10 @@ void thread_local_store_release(struct thread_local_store *t); * ========================== */ #define THREAD_LOCAL_VAR_ALLOC_FUNC_DEF(name, arg_name) void name(void *arg_name) -typedef THREAD_LOCAL_VAR_ALLOC_FUNC_DEF(thread_local_var_alloc_func, tls_struct); +typedef THREAD_LOCAL_VAR_ALLOC_FUNC_DEF(thread_local_var_alloc_func, ptr); #define THREAD_LOCAL_VAR_RELEASE_FUNC_DEF(name, arg_name) void name(void *arg_name) -typedef THREAD_LOCAL_VAR_RELEASE_FUNC_DEF(thread_local_var_release_func, tls_struct); +typedef THREAD_LOCAL_VAR_RELEASE_FUNC_DEF(thread_local_var_release_func, ptr); struct thread_local_var_meta { struct atomic_u64 id_plus_one; diff --git a/src/work.c b/src/work.c index dc7cf701..c6aaf5f2 100644 --- a/src/work.c +++ b/src/work.c @@ -6,7 +6,7 @@ #include "memory.h" #include "string.h" #include "log.h" -#include "tls.h" +#include "thread_local.h" /* Terminology: *