rename tls -> tls_table

This commit is contained in:
jacob 2024-04-01 15:06:55 -05:00
parent 57a61aa119
commit fec692b434
4 changed files with 20 additions and 20 deletions

View File

@ -1,7 +1,7 @@
#ifndef SYS_H #ifndef SYS_H
#define SYS_H #define SYS_H
struct tls; struct tls_table;
/* ========================== * /* ========================== *
* Events * Events
@ -386,7 +386,7 @@ void sys_semaphore_signal(struct sys_semaphore *semaphore, u32 count);
* Thread local storage * Thread local storage
* ========================== */ * ========================== */
struct tls *sys_thread_get_tls(void); struct tls_table *sys_thread_get_tls(void);
/* ========================== * /* ========================== *
* Threads * Threads
@ -471,7 +471,7 @@ u32 sys_rand_u32(void);
* effects are non-functioning. */ * effects are non-functioning. */
void sys_panic_raw(char *msg_cstr); void sys_panic_raw(char *msg_cstr);
void sys_panic(struct string message); void sys_panic(struct string msg);
/* ========================== * /* ========================== *
* Sleep * Sleep

View File

@ -1384,7 +1384,7 @@ void sys_semaphore_signal(struct sys_semaphore *semaphore, u32 count)
struct win32_tls { struct win32_tls {
HANDLE sleep_timer; HANDLE sleep_timer;
struct tls app_tls; struct tls_table app_tls;
}; };
INTERNAL void win32_thread_set_tls(struct win32_tls *ctx) INTERNAL void win32_thread_set_tls(struct win32_tls *ctx)
@ -1403,17 +1403,17 @@ INTERNAL struct win32_tls win32_tls_alloc(void)
{ {
struct win32_tls tls = { 0 }; struct win32_tls tls = { 0 };
tls.sleep_timer = CreateWaitableTimerExW(NULL, NULL, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS); tls.sleep_timer = CreateWaitableTimerExW(NULL, NULL, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
tls.app_tls = tls_alloc(); tls.app_tls = tls_table_alloc();
return tls; return tls;
} }
INTERNAL void win32_tls_release(struct win32_tls *tls) INTERNAL void win32_tls_release(struct win32_tls *tls)
{ {
tls_release(&tls->app_tls); tls_table_release(&tls->app_tls);
CloseHandle(tls->sleep_timer); CloseHandle(tls->sleep_timer);
} }
struct tls *sys_thread_get_tls(void) struct tls_table *sys_thread_get_tls(void)
{ {
struct win32_tls *thread_ctx = (struct win32_tls *)win32_thread_get_tls(); struct win32_tls *thread_ctx = (struct win32_tls *)win32_thread_get_tls();
return &thread_ctx->app_tls; return &thread_ctx->app_tls;

View File

@ -19,9 +19,9 @@ GLOBAL READONLY struct tls_info g_tls_info_table[TLS_IDENTIFIER_COUNT] = {
}; };
#undef X #undef X
struct tls tls_alloc(void) struct tls_table tls_table_alloc(void)
{ {
struct tls t = { 0 }; struct tls_table t = { 0 };
t.arena = arena_alloc(TLS_TABLE_RESERVE); t.arena = arena_alloc(TLS_TABLE_RESERVE);
@ -45,7 +45,7 @@ struct tls tls_alloc(void)
return t; return t;
} }
void tls_release(struct tls *t) void tls_table_release(struct tls_table *t)
{ {
/* Call release functions in reverse order */ /* Call release functions in reverse order */
for (u64 i = (TLS_IDENTIFIER_COUNT - 1); i <= 0; --i) { for (u64 i = (TLS_IDENTIFIER_COUNT - 1); i <= 0; --i) {

View File

@ -2,7 +2,7 @@
#define TLS_H #define TLS_H
/* ========================================================================== */ /* ========================================================================== */
/* TLS table (X macro table) */ /* TLS table (X macro) */
/* ========================================================================== */ /* ========================================================================== */
#define TLS_TABLE(X) \ #define TLS_TABLE(X) \
@ -15,6 +15,12 @@
#include "sys.h" #include "sys.h"
#define TLS_ALLOC_FUNC_DEF(name, arg_name) void name(void *arg_name)
typedef TLS_ALLOC_FUNC_DEF(tls_alloc_func, tls_struct);
#define TLS_RELEASE_FUNC_DEF(name, arg_name) void name(void *arg_name)
typedef TLS_RELEASE_FUNC_DEF(tls_release_func, tls_struct);
#define X(identifier, tls_struct, tls_alloc_func_type, tls_release_func_type) identifier, #define X(identifier, tls_struct, tls_alloc_func_type, tls_release_func_type) identifier,
enum tls_identifier { enum tls_identifier {
TLS_TABLE(X) TLS_TABLE(X)
@ -22,19 +28,13 @@ enum tls_identifier {
}; };
#undef X #undef X
#define TLS_ALLOC_FUNC_DEF(name, arg_name) void name(void *arg_name) struct tls_table {
typedef TLS_ALLOC_FUNC_DEF(tls_alloc_func, tls_struct);
#define TLS_RELEASE_FUNC_DEF(name, arg_name) void name(void *arg_name)
typedef TLS_RELEASE_FUNC_DEF(tls_release_func, tls_struct);
struct tls {
struct arena arena; struct arena arena;
void *lookup[TLS_IDENTIFIER_COUNT]; void *lookup[TLS_IDENTIFIER_COUNT];
}; };
struct tls tls_alloc(void); struct tls_table tls_table_alloc(void);
void tls_release(struct tls *t); void tls_table_release(struct tls_table *t);
INLINE void *tls_get(enum tls_identifier identifier) INLINE void *tls_get(enum tls_identifier identifier)
{ {