rename tls -> thread_local
This commit is contained in:
parent
99f0414261
commit
d11d2d8309
@ -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))
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
@ -6,7 +6,7 @@
|
||||
#include "memory.h"
|
||||
#include "string.h"
|
||||
#include "log.h"
|
||||
#include "tls.h"
|
||||
#include "thread_local.h"
|
||||
|
||||
/* Terminology:
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user