eliminate r/w lock promotion concept

This commit is contained in:
Ryan Fleury
2024-11-04 13:30:10 -08:00
parent 4a0e21d447
commit 44b8c9e87c
7 changed files with 45 additions and 92 deletions
+13 -45
View File
@@ -1253,7 +1253,8 @@ ctrl_init(void)
for(U64 idx = 0; idx < ctrl_state->thread_reg_cache.stripes_count; idx += 1)
{
ctrl_state->thread_reg_cache.stripes[idx].arena = arena_alloc();
ctrl_state->thread_reg_cache.stripes[idx].rw_mutex = os_rw_mutex_alloc();
ctrl_state->thread_reg_cache.stripes[idx].r_mutex = os_rw_mutex_alloc();
ctrl_state->thread_reg_cache.stripes[idx].w_mutex = os_rw_mutex_alloc();
}
ctrl_state->module_image_info_cache.slots_count = 1024;
ctrl_state->module_image_info_cache.slots = push_array(arena, CTRL_ModuleImageInfoCacheSlot, ctrl_state->module_image_info_cache.slots_count);
@@ -1779,7 +1780,7 @@ ctrl_query_cached_reg_block_from_thread(Arena *arena, CTRL_EntityStore *store, C
CTRL_ThreadRegCacheSlot *slot = &cache->slots[slot_idx];
CTRL_ThreadRegCacheStripe *stripe = &cache->stripes[stripe_idx];
void *result = push_array(arena, U8, reg_block_size);
OS_MutexScopeR(stripe->rw_mutex)
OS_MutexScopeR(stripe->r_mutex)
{
// rjf: find existing node
CTRL_ThreadRegCacheNode *node = 0;
@@ -1793,35 +1794,13 @@ ctrl_query_cached_reg_block_from_thread(Arena *arena, CTRL_EntityStore *store, C
}
// rjf: allocate existing node
if(!node)
if(!node) OS_MutexScopeW(stripe->w_mutex)
{
OS_MutexScopeRWPromote(stripe->rw_mutex)
{
for(CTRL_ThreadRegCacheNode *n = slot->first; n != 0; n = n->next)
{
if(ctrl_handle_match(n->handle, handle))
{
node = n;
break;
}
}
if(!node)
{
node = push_array(stripe->arena, CTRL_ThreadRegCacheNode, 1);
DLLPushBack(slot->first, slot->last, node);
node->handle = handle;
node->block_size = reg_block_size;
node->block = push_array(stripe->arena, U8, reg_block_size);
}
}
for(CTRL_ThreadRegCacheNode *n = slot->first; n != 0; n = n->next)
{
if(ctrl_handle_match(n->handle, handle))
{
node = n;
break;
}
}
node = push_array(stripe->arena, CTRL_ThreadRegCacheNode, 1);
DLLPushBack(slot->first, slot->last, node);
node->handle = handle;
node->block_size = reg_block_size;
node->block = push_array(stripe->arena, U8, reg_block_size);
}
// rjf: copy from node
@@ -1831,22 +1810,11 @@ ctrl_query_cached_reg_block_from_thread(Arena *arena, CTRL_EntityStore *store, C
B32 need_stale = 1;
if(node->reg_gen != current_reg_gen && dmn_thread_read_reg_block(handle.dmn_handle, result))
{
OS_MutexScopeRWPromote(stripe->rw_mutex)
OS_MutexScopeW(stripe->w_mutex) if(node != 0)
{
for(CTRL_ThreadRegCacheNode *n = slot->first; n != 0; n = n->next)
{
if(ctrl_handle_match(n->handle, handle))
{
node = n;
break;
}
}
if(node != 0)
{
need_stale = 0;
node->reg_gen = current_reg_gen;
MemoryCopy(node->block, result, reg_block_size);
}
need_stale = 0;
node->reg_gen = current_reg_gen;
MemoryCopy(node->block, result, reg_block_size);
}
}
if(need_stale)