mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-06 22:08:41 +00:00
eliminate text cache scope; fold into base layer's 'access' construct
This commit is contained in:
@@ -500,7 +500,6 @@ dasm_tick(void)
|
|||||||
U64 req_idx = req_num-1;
|
U64 req_idx = req_num-1;
|
||||||
Access *access = access_open();
|
Access *access = access_open();
|
||||||
DI_Scope *di_scope = di_scope_open();
|
DI_Scope *di_scope = di_scope_open();
|
||||||
TXT_Scope *txt_scope = txt_scope_open();
|
|
||||||
|
|
||||||
//- rjf: unpack
|
//- rjf: unpack
|
||||||
B32 stale = 0;
|
B32 stale = 0;
|
||||||
@@ -597,7 +596,7 @@ dasm_tick(void)
|
|||||||
TXT_LangKind lang_kind = txt_lang_kind_from_extension(file_normalized_full_path);
|
TXT_LangKind lang_kind = txt_lang_kind_from_extension(file_normalized_full_path);
|
||||||
U64 endt_us = max_U64;
|
U64 endt_us = max_U64;
|
||||||
U128 hash = {0};
|
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()));
|
stale = (stale || u128_match(hash, u128_zero()));
|
||||||
if(0 < line->line_num && line->line_num < text_info.lines_count)
|
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);
|
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);
|
di_scope_close(di_scope);
|
||||||
access_close(access);
|
access_close(access);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16092,13 +16092,12 @@ rd_frame(void)
|
|||||||
case RD_CmdKind_ToggleWatchExpressionAtCursor:
|
case RD_CmdKind_ToggleWatchExpressionAtCursor:
|
||||||
{
|
{
|
||||||
Access *access = access_open();
|
Access *access = access_open();
|
||||||
TXT_Scope *txt_scope = txt_scope_open();
|
|
||||||
RD_Regs *regs = rd_regs();
|
RD_Regs *regs = rd_regs();
|
||||||
C_Key text_key = regs->text_key;
|
C_Key text_key = regs->text_key;
|
||||||
TXT_LangKind lang_kind = regs->lang_kind;
|
TXT_LangKind lang_kind = regs->lang_kind;
|
||||||
TxtRng range = txt_rng(regs->cursor, regs->mark);
|
TxtRng range = txt_rng(regs->cursor, regs->mark);
|
||||||
U128 hash = {0};
|
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);
|
String8 data = c_data_from_hash(access, hash);
|
||||||
Rng1U64 expr_off_range = {0};
|
Rng1U64 expr_off_range = {0};
|
||||||
if(range.min.column != range.max.column)
|
if(range.min.column != range.max.column)
|
||||||
@@ -16114,7 +16113,6 @@ rd_frame(void)
|
|||||||
kind == RD_CmdKind_ToggleWatchExpressionAtCursor ? RD_CmdKind_ToggleWatchExpression :
|
kind == RD_CmdKind_ToggleWatchExpressionAtCursor ? RD_CmdKind_ToggleWatchExpression :
|
||||||
RD_CmdKind_GoToName),
|
RD_CmdKind_GoToName),
|
||||||
.string = expr);
|
.string = expr);
|
||||||
txt_scope_close(txt_scope);
|
|
||||||
access_close(access);
|
access_close(access);
|
||||||
}break;
|
}break;
|
||||||
case RD_CmdKind_SetNextStatement:
|
case RD_CmdKind_SetNextStatement:
|
||||||
|
|||||||
@@ -2026,7 +2026,6 @@ RD_VIEW_UI_FUNCTION_DEF(text)
|
|||||||
rd_code_view_init(cv);
|
rd_code_view_init(cv);
|
||||||
Temp scratch = scratch_begin(0, 0);
|
Temp scratch = scratch_begin(0, 0);
|
||||||
Access *access = access_open();
|
Access *access = access_open();
|
||||||
TXT_Scope *txt_scope = txt_scope_open();
|
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- rjf: set up invariants
|
//- rjf: set up invariants
|
||||||
@@ -2090,7 +2089,7 @@ RD_VIEW_UI_FUNCTION_DEF(text)
|
|||||||
rd_regs()->lang_kind = txt_lang_kind_from_extension(lang);
|
rd_regs()->lang_kind = txt_lang_kind_from_extension(lang);
|
||||||
}
|
}
|
||||||
U128 hash = {0};
|
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);
|
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 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;
|
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_line"), rd_regs()->mark.line);
|
||||||
rd_store_view_param_s64(str8_lit("mark_column"), rd_regs()->mark.column);
|
rd_store_view_param_s64(str8_lit("mark_column"), rd_regs()->mark.column);
|
||||||
|
|
||||||
txt_scope_close(txt_scope);
|
|
||||||
access_close(access);
|
access_close(access);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
@@ -2292,7 +2290,6 @@ RD_VIEW_UI_FUNCTION_DEF(disasm)
|
|||||||
RD_CodeViewState *cv = &dv->cv;
|
RD_CodeViewState *cv = &dv->cv;
|
||||||
Temp scratch = scratch_begin(0, 0);
|
Temp scratch = scratch_begin(0, 0);
|
||||||
Access *access = access_open();
|
Access *access = access_open();
|
||||||
TXT_Scope *txt_scope = txt_scope_open();
|
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- rjf: if disassembly views are not parameterized by anything, they
|
//- 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()->text_key = dasm_info.text_key;
|
||||||
rd_regs()->lang_kind = txt_lang_kind_from_arch(arch);
|
rd_regs()->lang_kind = txt_lang_kind_from_arch(arch);
|
||||||
U128 dasm_text_hash = {0};
|
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);
|
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 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));
|
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->cursor = rd_regs()->cursor;
|
||||||
dv->mark = rd_regs()->mark;
|
dv->mark = rd_regs()->mark;
|
||||||
|
|
||||||
txt_scope_close(txt_scope);
|
|
||||||
access_close(access);
|
access_close(access);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1617,93 +1617,11 @@ txt_init(void)
|
|||||||
txt_shared->evictor_thread = thread_launch(txt_evictor_thread__entry_point, 0);
|
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
|
//~ rjf: Cache Lookups
|
||||||
|
|
||||||
internal TXT_TextInfo
|
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};
|
TXT_TextInfo info = {0};
|
||||||
if(!u128_match(hash, u128_zero()))
|
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_processed = ins_atomic_u64_eval(&n->info.bytes_processed);
|
||||||
info.bytes_to_process = ins_atomic_u64_eval(&n->info.bytes_to_process);
|
info.bytes_to_process = ins_atomic_u64_eval(&n->info.bytes_to_process);
|
||||||
found = 1;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1771,13 +1691,13 @@ txt_text_info_from_hash_lang(TXT_Scope *scope, U128 hash, TXT_LangKind lang)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal TXT_TextInfo
|
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};
|
TXT_TextInfo result = {0};
|
||||||
for(U64 rewind_idx = 0; rewind_idx < C_KEY_HASH_HISTORY_COUNT; rewind_idx += 1)
|
for(U64 rewind_idx = 0; rewind_idx < C_KEY_HASH_HISTORY_COUNT; rewind_idx += 1)
|
||||||
{
|
{
|
||||||
U128 hash = c_hash_from_key(key, rewind_idx);
|
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(result.lines_count != 0)
|
||||||
{
|
{
|
||||||
if(hash_out)
|
if(hash_out)
|
||||||
|
|||||||
@@ -196,35 +196,6 @@ struct TXT_Stripe
|
|||||||
CondVar cv;
|
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
|
//~ rjf: Shared State
|
||||||
|
|
||||||
@@ -259,7 +230,6 @@ struct TXT_Shared
|
|||||||
//~ rjf: Globals
|
//~ rjf: Globals
|
||||||
|
|
||||||
read_only global TXT_ScopeNode txt_scope_node_nil = {0};
|
read_only global TXT_ScopeNode txt_scope_node_nil = {0};
|
||||||
thread_static TXT_TCTX *txt_tctx = 0;
|
|
||||||
global TXT_Shared *txt_shared = 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);
|
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
|
//~ 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_hash_lang(Access *access, 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_key_lang(Access *access, C_Key key, TXT_LangKind lang, U128 *hash_out);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Text Info Extractor Helpers
|
//~ rjf: Text Info Extractor Helpers
|
||||||
|
|||||||
Reference in New Issue
Block a user