promote content scope to base layer, rename as 'access'; generalize based just on list of scope refcounts, + optional cvs; eliminate c_scope; replace dasm_scope with access as well

This commit is contained in:
Ryan Fleury
2025-09-18 15:21:22 -07:00
parent 5381307e90
commit 1b93dbd4bd
15 changed files with 203 additions and 308 deletions
+55
View File
@@ -130,3 +130,58 @@ tctx_read_srcloc(char **file_name, U64 *line_number)
*file_name = tctx->file_name;
*line_number = tctx->line_number;
}
////////////////////////////////
//~ rjf: Touch Scope Functions
internal Access *
access_open(void)
{
if(tctx_thread_local->access_arena == 0)
{
tctx_thread_local->access_arena = arena_alloc();
}
Access *access = tctx_thread_local->free_access;
if(access != 0)
{
SLLStackPop(tctx_thread_local->free_access);
}
else
{
access = push_array_no_zero(tctx_thread_local->access_arena, Access, 1);
}
MemoryZeroStruct(access);
return access;
}
internal void
access_close(Access *access)
{
for(Touch *touch = access->top_touch, *next = 0; touch != 0; touch = next)
{
next = touch->next;
ins_atomic_u64_dec_eval(touch->touch_count);
if(touch->cv.u64[0] != 0) { cond_var_broadcast(touch->cv); }
SLLStackPush(tctx_thread_local->free_touch, touch);
}
SLLStackPush(tctx_thread_local->free_access, access);
}
internal void
access_touch(Access *access, U64 *touch_count, CondVar cv)
{
ins_atomic_u64_inc_eval(touch_count);
Touch *touch = tctx_thread_local->free_touch;
if(touch != 0)
{
SLLStackPop(tctx_thread_local->free_touch);
}
else
{
touch = push_array_no_zero(tctx_thread_local->access_arena, Touch, 1);
}
MemoryZeroStruct(touch);
SLLStackPush(access->top_touch, touch);
touch->cv = cv;
touch->touch_count = touch_count;
}
+28
View File
@@ -15,6 +15,24 @@ struct LaneCtx
Barrier barrier;
};
////////////////////////////////
//~ rjf: Access Scopes
typedef struct Touch Touch;
struct Touch
{
Touch *next;
U64 *touch_count;
CondVar cv;
};
typedef struct Access Access;
struct Access
{
Access *next;
Touch *top_touch;
};
////////////////////////////////
//~ rjf: Base Per-Thread State Bundle
@@ -34,6 +52,11 @@ struct TCTX
// rjf: source location info
char *file_name;
U64 line_number;
// rjf: accesses
Arena *access_arena;
Access *free_access;
Touch *free_touch;
};
////////////////////////////////
@@ -69,4 +92,9 @@ internal void tctx_write_srcloc(char *file_name, U64 line_number);
internal void tctx_read_srcloc(char **file_name, U64 *line_number);
#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
//- rjf: access scopes
internal Access *access_open(void);
internal void access_close(Access *access);
internal void access_touch(Access *access, U64 *touch_count, CondVar cv);
#endif // BASE_THREAD_CONTEXT_H