FiberId as a macro
This commit is contained in:
parent
03f4b71892
commit
ca9639affb
@ -631,6 +631,15 @@ Struct(StringList)
|
||||
u64 count;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Fiber id
|
||||
|
||||
#if PlatformIsWindows
|
||||
# define FiberId *(i16 *)(void *)(volatile u64)__readgsqword(32)
|
||||
#else
|
||||
# error FiberId not implemented
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdecl Core hooks
|
||||
|
||||
@ -639,8 +648,6 @@ StringList GetCommandLineArgs(void);
|
||||
b32 Panic(String msg);
|
||||
b32 IsRunningInDebugger(void);
|
||||
void TrueRand(String buffer);
|
||||
ForceInline i16 FiberId(void);
|
||||
ForceInline i16 ThreadId(void);
|
||||
|
||||
#define MaxThreads 1024
|
||||
#define MaxFibers 1024
|
||||
|
||||
@ -180,8 +180,8 @@ Inline void EndTempArena(TempArena temp)
|
||||
|
||||
Inline ArenaCtx *ArenaCtxFromFiberId(i16 fiber_id)
|
||||
{
|
||||
SharedArenaCtx *shared = &shared_arena_ctx;
|
||||
ArenaCtx *ctx = &shared->arena_contexts[fiber_id];
|
||||
SharedArenaCtx *g = &shared_arena_ctx;
|
||||
ArenaCtx *ctx = &g->arena_contexts[fiber_id];
|
||||
if (!ctx->scratch_arenas[0])
|
||||
{
|
||||
__profn("Initialize fiber arena ctx");
|
||||
@ -205,9 +205,7 @@ Inline ArenaCtx *ArenaCtxFromFiberId(i16 fiber_id)
|
||||
*
|
||||
* Use `BeginScratchNoConflict` instead if there is no arena in the current
|
||||
* scope that could potentially be a scratch arena from another scope. */
|
||||
#define BeginScratch(potential_conflict) _BeginScratch(potential_conflict)
|
||||
|
||||
Inline TempArena _BeginScratch(Arena *potential_conflict)
|
||||
Inline TempArena BeginScratch(Arena *potential_conflict)
|
||||
{
|
||||
/* This function is currently hard-coded to support 2 scratch arenas */
|
||||
StaticAssert(ScratchArenasPerCtx == 2);
|
||||
@ -215,7 +213,7 @@ Inline TempArena _BeginScratch(Arena *potential_conflict)
|
||||
/* Use `BeginScratchNoConflict` if no conflicts are present */
|
||||
Assert(potential_conflict != 0);
|
||||
|
||||
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId());
|
||||
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId);
|
||||
Arena *scratch_arena = ctx->scratch_arenas[0];
|
||||
if (potential_conflict && scratch_arena == potential_conflict)
|
||||
{
|
||||
@ -239,7 +237,7 @@ Inline TempArena _BeginScratch(Arena *potential_conflict)
|
||||
|
||||
Inline TempArena BeginScratchNoConflict_(void)
|
||||
{
|
||||
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId());
|
||||
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId);
|
||||
Arena *scratch_arena = ctx->scratch_arenas[0];
|
||||
TempArena temp = BeginTempArena(scratch_arena);
|
||||
return temp;
|
||||
@ -255,6 +253,6 @@ Inline void EndScratch(TempArena scratch_temp)
|
||||
|
||||
Inline Arena *GetPermArena(void)
|
||||
{
|
||||
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId());
|
||||
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId);
|
||||
return ctx->perm_arena;
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ Lock LockSpinE(Mutex *m, i32 spin)
|
||||
}
|
||||
|
||||
#if RtcIsEnabled
|
||||
Atomic32FetchSet(&m->exclusive_fiber_id, FiberId());
|
||||
Atomic32FetchSet(&m->exclusive_fiber_id, FiberId);
|
||||
#endif
|
||||
|
||||
Lock lock = ZI;
|
||||
|
||||
@ -46,20 +46,6 @@ b32 IsRunningInDebugger(void)
|
||||
return IsDebuggerPresent();
|
||||
}
|
||||
|
||||
//- Fiber id
|
||||
ForceInline i16 FiberId(void)
|
||||
{
|
||||
i16 *v = (void *)(u64)__readgsqword(32);
|
||||
return *v;
|
||||
}
|
||||
|
||||
//- Thread id
|
||||
ForceInline i16 ThreadId(void)
|
||||
{
|
||||
W32_SharedState *g = &W32_shared_state;
|
||||
return (i16)(i64)TlsGetValue(g->tls_index);
|
||||
}
|
||||
|
||||
//- True randomness
|
||||
void TrueRand(String buffer)
|
||||
{
|
||||
|
||||
@ -829,7 +829,7 @@ ForceNoInline void W32_FiberResume(W32_Fiber *fiber)
|
||||
void W32_YieldFiber(W32_Fiber *fiber, W32_Fiber *parent_fiber)
|
||||
{
|
||||
LAX fiber;
|
||||
Assert(fiber->id == FiberId());
|
||||
Assert(fiber->id == FiberId);
|
||||
Assert(parent_fiber->id == fiber->parent_id);
|
||||
Assert(parent_fiber->id > 0);
|
||||
{
|
||||
@ -948,7 +948,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
|
||||
}
|
||||
}
|
||||
|
||||
i32 worker_fiber_id = FiberId();
|
||||
i32 worker_fiber_id = FiberId;
|
||||
|
||||
W32_Fiber *job_fiber = 0;
|
||||
b32 shutdown = 0;
|
||||
@ -1343,7 +1343,7 @@ W32_ThreadDef(W32_JobSchedulerEntryFunc, UNUSED arg)
|
||||
|
||||
void FutexYield(volatile void *addr, void *cmp, u32 size, i64 timeout_ns)
|
||||
{
|
||||
W32_Fiber *fiber = W32_FiberFromId(FiberId());
|
||||
W32_Fiber *fiber = W32_FiberFromId(FiberId);
|
||||
i16 parent_id = fiber->parent_id;
|
||||
if (parent_id != 0)
|
||||
{
|
||||
@ -1435,7 +1435,7 @@ void RunJobEx(GenericJobDesc *desc)
|
||||
{
|
||||
AddCounter(counter, 1);
|
||||
}
|
||||
W32_Fiber *fiber = W32_FiberFromId(FiberId());
|
||||
W32_Fiber *fiber = W32_FiberFromId(FiberId);
|
||||
priority = ClampI32(priority, fiber->job_priority, JobPriority_Count - 1); /* A job cannot create a job with a higher priority than itself */
|
||||
if (pool_kind == JobPool_Inherit)
|
||||
{
|
||||
|
||||
@ -854,6 +854,10 @@ void StartupMeta(void)
|
||||
PushStringToList(arena, &c_out_lines, Lit("//- Startup"));
|
||||
PushStringToList(arena, &c_out_lines, Lit("void StartupLayers(void)"));
|
||||
PushStringToList(arena, &c_out_lines, Lit("{"));
|
||||
{
|
||||
String line = Lit(" StartupBase();");
|
||||
PushStringToList(arena, &c_out_lines, line);
|
||||
}
|
||||
for (L_TopoItem *item = topo.startup_functions.first; item; item = item->next)
|
||||
{
|
||||
String line = StringF(arena, " %F();", FmtString(item->s));
|
||||
|
||||
@ -151,8 +151,9 @@ void P_Log_(i32 level, String msg)
|
||||
}
|
||||
|
||||
|
||||
u32 tid = ThreadId();
|
||||
|
||||
/* FIXME: Log actual thread & fiber id */
|
||||
// u32 tid = ThreadId();
|
||||
u32 tid = 0;
|
||||
|
||||
//- Format message
|
||||
P_DateTime datetime = P_LocalTime();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user