eliminate text cache scope; fold into base layer's 'access' construct

This commit is contained in:
Ryan Fleury
2025-09-18 15:25:11 -07:00
parent 1b93dbd4bd
commit 2131e792a1
5 changed files with 12 additions and 142 deletions
+6 -86
View File
@@ -1617,93 +1617,11 @@ txt_init(void)
txt_shared->evictor_thread = thread_launch(txt_evictor_thread__entry_point, 0);
}
////////////////////////////////
//~ rjf: Thread Context Initialization
internal void
txt_tctx_ensure_inited(void)
{
if(txt_tctx == 0)
{
Arena *arena = arena_alloc();
txt_tctx = push_array(arena, TXT_TCTX, 1);
txt_tctx->arena = arena;
}
}
////////////////////////////////
//~ rjf: Scoped Access
internal TXT_Scope *
txt_scope_open(void)
{
txt_tctx_ensure_inited();
TXT_Scope *scope = txt_tctx->free_scope;
if(scope)
{
SLLStackPop(txt_tctx->free_scope);
}
else
{
scope = push_array_no_zero(txt_tctx->arena, TXT_Scope, 1);
}
MemoryZeroStruct(scope);
return scope;
}
internal void
txt_scope_close(TXT_Scope *scope)
{
for(TXT_Touch *touch = scope->top_touch, *next = 0; touch != 0; touch = next)
{
U128 hash = touch->hash;
next = touch->next;
U64 slot_idx = hash.u64[1]%txt_shared->slots_count;
U64 stripe_idx = slot_idx%txt_shared->stripes_count;
TXT_Slot *slot = &txt_shared->slots[slot_idx];
TXT_Stripe *stripe = &txt_shared->stripes[stripe_idx];
MutexScopeR(stripe->rw_mutex)
{
for(TXT_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(hash, n->hash) && touch->lang == n->lang)
{
ins_atomic_u64_dec_eval(&n->scope_ref_count);
break;
}
}
}
SLLStackPush(txt_tctx->free_touch, touch);
}
SLLStackPush(txt_tctx->free_scope, scope);
}
internal void
txt_scope_touch_node__stripe_r_guarded(TXT_Scope *scope, TXT_Node *node)
{
TXT_Touch *touch = txt_tctx->free_touch;
ins_atomic_u64_inc_eval(&node->scope_ref_count);
ins_atomic_u64_eval_assign(&node->last_time_touched_us, os_now_microseconds());
ins_atomic_u64_eval_assign(&node->last_user_clock_idx_touched, update_tick_idx());
if(touch != 0)
{
SLLStackPop(txt_tctx->free_touch);
}
else
{
touch = push_array_no_zero(txt_tctx->arena, TXT_Touch, 1);
}
MemoryZeroStruct(touch);
touch->hash = node->hash;
touch->lang = node->lang;
SLLStackPush(scope->top_touch, touch);
}
////////////////////////////////
//~ rjf: Cache Lookups
internal TXT_TextInfo
txt_text_info_from_hash_lang(TXT_Scope *scope, U128 hash, TXT_LangKind lang)
txt_text_info_from_hash_lang(Access *access, U128 hash, TXT_LangKind lang)
{
TXT_TextInfo info = {0};
if(!u128_match(hash, u128_zero()))
@@ -1723,7 +1641,9 @@ txt_text_info_from_hash_lang(TXT_Scope *scope, U128 hash, TXT_LangKind lang)
info.bytes_processed = ins_atomic_u64_eval(&n->info.bytes_processed);
info.bytes_to_process = ins_atomic_u64_eval(&n->info.bytes_to_process);
found = 1;
txt_scope_touch_node__stripe_r_guarded(scope, n);
ins_atomic_u64_eval_assign(&n->last_time_touched_us, os_now_microseconds());
ins_atomic_u64_eval_assign(&n->last_user_clock_idx_touched, update_tick_idx());
access_touch(access, &n->scope_ref_count, stripe->cv);
break;
}
}
@@ -1771,13 +1691,13 @@ txt_text_info_from_hash_lang(TXT_Scope *scope, U128 hash, TXT_LangKind lang)
}
internal TXT_TextInfo
txt_text_info_from_key_lang(TXT_Scope *scope, C_Key key, TXT_LangKind lang, U128 *hash_out)
txt_text_info_from_key_lang(Access *access, C_Key key, TXT_LangKind lang, U128 *hash_out)
{
TXT_TextInfo result = {0};
for(U64 rewind_idx = 0; rewind_idx < C_KEY_HASH_HISTORY_COUNT; rewind_idx += 1)
{
U128 hash = c_hash_from_key(key, rewind_idx);
result = txt_text_info_from_hash_lang(scope, hash, lang);
result = txt_text_info_from_hash_lang(access, hash, lang);
if(result.lines_count != 0)
{
if(hash_out)
+2 -44
View File
@@ -196,35 +196,6 @@ struct TXT_Stripe
CondVar cv;
};
////////////////////////////////
//~ rjf: Scoped Access
typedef struct TXT_Touch TXT_Touch;
struct TXT_Touch
{
TXT_Touch *next;
U128 hash;
TXT_LangKind lang;
};
typedef struct TXT_Scope TXT_Scope;
struct TXT_Scope
{
TXT_Scope *next;
TXT_Touch *top_touch;
};
////////////////////////////////
//~ rjf: Thread Context
typedef struct TXT_TCTX TXT_TCTX;
struct TXT_TCTX
{
Arena *arena;
TXT_Scope *free_scope;
TXT_Touch *free_touch;
};
////////////////////////////////
//~ rjf: Shared State
@@ -259,7 +230,6 @@ struct TXT_Shared
//~ rjf: Globals
read_only global TXT_ScopeNode txt_scope_node_nil = {0};
thread_static TXT_TCTX *txt_tctx = 0;
global TXT_Shared *txt_shared = 0;
////////////////////////////////
@@ -292,23 +262,11 @@ internal TXT_TokenArray txt_token_array_from_string__disasm_x64_intel(Arena *are
internal void txt_init(void);
////////////////////////////////
//~ rjf: Thread Context Initialization
internal void txt_tctx_ensure_inited(void);
////////////////////////////////
//~ rjf: Scoped Access
internal TXT_Scope *txt_scope_open(void);
internal void txt_scope_close(TXT_Scope *scope);
internal void txt_scope_touch_node__stripe_r_guarded(TXT_Scope *scope, TXT_Node *node);
////////////////////////////////
//~ rjf: Cache Lookups
internal TXT_TextInfo txt_text_info_from_hash_lang(TXT_Scope *scope, U128 hash, TXT_LangKind lang);
internal TXT_TextInfo txt_text_info_from_key_lang(TXT_Scope *scope, C_Key key, TXT_LangKind lang, U128 *hash_out);
internal TXT_TextInfo txt_text_info_from_hash_lang(Access *access, U128 hash, TXT_LangKind lang);
internal TXT_TextInfo txt_text_info_from_key_lang(Access *access, C_Key key, TXT_LangKind lang, U128 *hash_out);
////////////////////////////////
//~ rjf: Text Info Extractor Helpers