mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-07-26 01:13:44 +00:00
txti -> txt; checkpoint #1
This commit is contained in:
@@ -37,55 +37,71 @@ fs_init(void)
|
||||
//~ rjf: Cache Interaction
|
||||
|
||||
internal U128
|
||||
fs_hash_from_path(String8 path, U64 rewind_count, U64 endt_us)
|
||||
fs_hash_from_path(String8 path, U64 endt_us)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
U128 result = {0};
|
||||
path = path_normalized_from_string(scratch.arena, path);
|
||||
U128 path_key = hs_hash_from_data(path);
|
||||
U128 result = hs_hash_from_key(path_key, rewind_count);
|
||||
if(u128_match(result, u128_zero()))
|
||||
for(U64 rewind_idx = 0; rewind_idx < 2; rewind_idx += 1)
|
||||
{
|
||||
U64 slot_idx = path_key.u64[0]%fs_shared->slots_count;
|
||||
U64 stripe_idx = slot_idx%fs_shared->stripes_count;
|
||||
FS_Slot *slot = &fs_shared->slots[slot_idx];
|
||||
FS_Stripe *stripe = &fs_shared->stripes[stripe_idx];
|
||||
OS_MutexScopeR(stripe->rw_mutex) for(;;)
|
||||
result = hs_hash_from_key(path_key, rewind_idx);
|
||||
if(!u128_match(result, u128_zero()))
|
||||
{
|
||||
FS_Node *node = 0;
|
||||
for(FS_Node *n = slot->first; n != 0; n = n->next)
|
||||
break;
|
||||
}
|
||||
else if(u128_match(result, u128_zero()) && rewind_idx == 0)
|
||||
{
|
||||
U64 slot_idx = path_key.u64[0]%fs_shared->slots_count;
|
||||
U64 stripe_idx = slot_idx%fs_shared->stripes_count;
|
||||
FS_Slot *slot = &fs_shared->slots[slot_idx];
|
||||
FS_Stripe *stripe = &fs_shared->stripes[stripe_idx];
|
||||
OS_MutexScopeR(stripe->rw_mutex) for(;;)
|
||||
{
|
||||
if(str8_match(path, n->path, 0))
|
||||
FS_Node *node = 0;
|
||||
for(FS_Node *n = slot->first; n != 0; n = n->next)
|
||||
{
|
||||
if(str8_match(path, n->path, 0))
|
||||
{
|
||||
node = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(node == 0) OS_MutexScopeRWPromote(stripe->rw_mutex)
|
||||
{
|
||||
node = push_array(stripe->arena, FS_Node, 1);
|
||||
SLLQueuePush(slot->first, slot->last, node);
|
||||
node->path = push_str8_copy(stripe->arena, path);
|
||||
}
|
||||
if(os_now_microseconds() >= ins_atomic_u64_eval(&node->last_time_requested_us)+1000000 &&
|
||||
fs_u2s_enqueue_path(path, endt_us))
|
||||
{
|
||||
ins_atomic_u64_eval_assign(&node->last_time_requested_us, os_now_microseconds());
|
||||
}
|
||||
result = hs_hash_from_key(path_key, 0);
|
||||
if(u128_match(result, u128_zero()) && os_now_microseconds() <= endt_us)
|
||||
{
|
||||
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(node == 0) OS_MutexScopeRWPromote(stripe->rw_mutex)
|
||||
{
|
||||
node = push_array(stripe->arena, FS_Node, 1);
|
||||
SLLQueuePush(slot->first, slot->last, node);
|
||||
node->path = push_str8_copy(stripe->arena, path);
|
||||
}
|
||||
if(os_now_microseconds() >= ins_atomic_u64_eval(&node->last_time_requested_us)+1000000 &&
|
||||
fs_u2s_enqueue_path(path, endt_us))
|
||||
{
|
||||
ins_atomic_u64_eval_assign(&node->last_time_requested_us, os_now_microseconds());
|
||||
}
|
||||
result = hs_hash_from_key(path_key, rewind_count);
|
||||
if(u128_match(result, u128_zero()) && os_now_microseconds() <= endt_us)
|
||||
{
|
||||
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal U128
|
||||
fs_key_from_path(String8 path)
|
||||
{
|
||||
U128 key = hs_hash_from_data(path);
|
||||
fs_hash_from_path(path, 0);
|
||||
return key;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Streamer Threads
|
||||
|
||||
|
||||
@@ -74,7 +74,8 @@ internal void fs_init(void);
|
||||
////////////////////////////////
|
||||
//~ rjf: Cache Interaction
|
||||
|
||||
internal U128 fs_hash_from_path(String8 path, U64 rewind_count, U64 endt_us);
|
||||
internal U128 fs_hash_from_path(String8 path, U64 endt_us);
|
||||
internal U128 fs_key_from_path(String8 path);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Streamer Threads
|
||||
|
||||
Reference in New Issue
Block a user