diff --git a/src/dasm_cache/dasm_cache.c b/src/dasm_cache/dasm_cache.c index 991a067e..601f0497 100644 --- a/src/dasm_cache/dasm_cache.c +++ b/src/dasm_cache/dasm_cache.c @@ -500,7 +500,6 @@ dasm_tick(void) U64 req_idx = req_num-1; Access *access = access_open(); DI_Scope *di_scope = di_scope_open(); - TXT_Scope *txt_scope = txt_scope_open(); //- rjf: unpack B32 stale = 0; @@ -597,7 +596,7 @@ dasm_tick(void) TXT_LangKind lang_kind = txt_lang_kind_from_extension(file_normalized_full_path); U64 endt_us = max_U64; U128 hash = {0}; - TXT_TextInfo text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash); + TXT_TextInfo text_info = txt_text_info_from_key_lang(access, key, lang_kind, &hash); stale = (stale || u128_match(hash, u128_zero())); if(0 < line->line_num && line->line_num < text_info.lines_count) { @@ -730,7 +729,6 @@ dasm_tick(void) req_n->v.params.dbgi_key = di_key_copy(dasm_shared->req_arena, &req_n->v.params.dbgi_key); } - txt_scope_close(txt_scope); di_scope_close(di_scope); access_close(access); } diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index eff206bc..1e1dce0d 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -16092,13 +16092,12 @@ rd_frame(void) case RD_CmdKind_ToggleWatchExpressionAtCursor: { Access *access = access_open(); - TXT_Scope *txt_scope = txt_scope_open(); RD_Regs *regs = rd_regs(); C_Key text_key = regs->text_key; TXT_LangKind lang_kind = regs->lang_kind; TxtRng range = txt_rng(regs->cursor, regs->mark); U128 hash = {0}; - TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, text_key, lang_kind, &hash); + TXT_TextInfo info = txt_text_info_from_key_lang(access, text_key, lang_kind, &hash); String8 data = c_data_from_hash(access, hash); Rng1U64 expr_off_range = {0}; if(range.min.column != range.max.column) @@ -16114,7 +16113,6 @@ rd_frame(void) kind == RD_CmdKind_ToggleWatchExpressionAtCursor ? RD_CmdKind_ToggleWatchExpression : RD_CmdKind_GoToName), .string = expr); - txt_scope_close(txt_scope); access_close(access); }break; case RD_CmdKind_SetNextStatement: diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index 74df242d..cd17f550 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -2026,7 +2026,6 @@ RD_VIEW_UI_FUNCTION_DEF(text) rd_code_view_init(cv); Temp scratch = scratch_begin(0, 0); Access *access = access_open(); - TXT_Scope *txt_scope = txt_scope_open(); ////////////////////////////// //- rjf: set up invariants @@ -2090,7 +2089,7 @@ RD_VIEW_UI_FUNCTION_DEF(text) rd_regs()->lang_kind = txt_lang_kind_from_extension(lang); } U128 hash = {0}; - TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, rd_regs()->text_key, rd_regs()->lang_kind, &hash); + TXT_TextInfo info = txt_text_info_from_key_lang(access, rd_regs()->text_key, rd_regs()->lang_kind, &hash); String8 data = c_data_from_hash(access, hash); B32 file_is_missing = (rd_regs()->file_path.size != 0 && os_properties_from_file_path(rd_regs()->file_path).modified == 0); B32 key_has_data = !u128_match(hash, u128_zero()) && info.lines_count; @@ -2250,7 +2249,6 @@ RD_VIEW_UI_FUNCTION_DEF(text) rd_store_view_param_s64(str8_lit("mark_line"), rd_regs()->mark.line); rd_store_view_param_s64(str8_lit("mark_column"), rd_regs()->mark.column); - txt_scope_close(txt_scope); access_close(access); scratch_end(scratch); } @@ -2292,7 +2290,6 @@ RD_VIEW_UI_FUNCTION_DEF(disasm) RD_CodeViewState *cv = &dv->cv; Temp scratch = scratch_begin(0, 0); Access *access = access_open(); - TXT_Scope *txt_scope = txt_scope_open(); ////////////////////////////// //- rjf: if disassembly views are not parameterized by anything, they @@ -2413,7 +2410,7 @@ RD_VIEW_UI_FUNCTION_DEF(disasm) rd_regs()->text_key = dasm_info.text_key; rd_regs()->lang_kind = txt_lang_kind_from_arch(arch); U128 dasm_text_hash = {0}; - TXT_TextInfo dasm_text_info = txt_text_info_from_key_lang(txt_scope, rd_regs()->text_key, rd_regs()->lang_kind, &dasm_text_hash); + TXT_TextInfo dasm_text_info = txt_text_info_from_key_lang(access, rd_regs()->text_key, rd_regs()->lang_kind, &dasm_text_hash); String8 dasm_text_data = c_data_from_hash(access, dasm_text_hash); B32 has_disasm = (dasm_info.lines.count != 0 && dasm_text_info.lines_count != 0); B32 is_loading = (!has_disasm && dim_1u64(range) != 0 && eval.msgs.max_kind == E_MsgKind_Null && (space.kind != RD_EvalSpaceKind_CtrlEntity || space_entity != &ctrl_entity_nil)); @@ -2494,7 +2491,6 @@ RD_VIEW_UI_FUNCTION_DEF(disasm) dv->cursor = rd_regs()->cursor; dv->mark = rd_regs()->mark; - txt_scope_close(txt_scope); access_close(access); scratch_end(scratch); } diff --git a/src/text_cache/text_cache.c b/src/text_cache/text_cache.c index 81508930..554c8dd1 100644 --- a/src/text_cache/text_cache.c +++ b/src/text_cache/text_cache.c @@ -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) diff --git a/src/text_cache/text_cache.h b/src/text_cache/text_cache.h index dac93a8c..abf41f24 100644 --- a/src/text_cache/text_cache.h +++ b/src/text_cache/text_cache.h @@ -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