TrinyxJobs namespace
TrinyxJobs — Lock-free job system for the Trinyx Trinity threading model.
Three queues with affinity: Physics — Brain (LogicThread) produces, workers + Brain consume Render — Encoder (VulkRender) produces, workers + Encoder consume General — any thread produces/consumes
Usage: TrinyxJobs::
Jolt integration: write a thin JPH::JobSystem adapter that maps CreateJob/QueueJob/Barrier onto Dispatch/WaitForCounter.
Classes
- struct Job
- struct JobCounter
Enums
Typedefs
- using WorldQueueHandle = uint32_t
Functions
- auto operator|(Queue a, Queue b) -> Queue constexpr
- auto operator&(Queue a, Queue b) -> Queue constexpr
- auto Initialize(const EngineConfig* config) -> bool
- Initialize queues and spawn worker threads (count from ThreadPinning).
- void Shutdown()
- Signal workers to stop and join all threads. Safe to call multiple times.
- auto IsRunning() -> bool
- void SubmitJob(const Job& job, Queue queue)
-
template<ValidJobLambda LAMBDA>void Dispatch(LAMBDA lambda, JobCounter* counter, Queue queue = Queue::General)
-
template<ValidNamedJobLambda LAMBDA>void DispatchNamed(const char* name, LAMBDA lambda, JobCounter* counter, Queue queue = Queue::General)
- void WaitForCounter(JobCounter* counter, Queue affinity = Queue::All)
- auto GetWorkerCount() -> uint32_t
- Number of active worker threads (excludes coordinators).
- auto GetCurrentThreadIndex() -> uint32_t
- Thread-local index of the current worker (0 = coordinator/non-worker).
- auto CreateWorldQueue(size_t capacity = 256) -> WorldQueueHandle
- void DestroyWorldQueue(WorldQueueHandle handle)
- void DrainWorldQueue(WorldQueueHandle handle)
- void SubmitWorldJob(const Job& job, WorldQueueHandle handle)
- Internal — called by Post/Spawn/SpawnAndWait templates.
-
template<ValidJobLambda LAMBDA>void Post(LAMBDA lambda, WorldQueueHandle handle)
-
template<ValidJobLambda LAMBDA>void Spawn(LAMBDA lambda, JobCounter* counter, WorldQueueHandle handle)
-
template<ValidJobLambda LAMBDA>void SpawnAndWait(LAMBDA lambda, WorldQueueHandle handle)
Variables
- static WorldQueueHandle InvalidWorldQueue constexpr
Enum documentation
enum class TrinyxJobs:: Queue: uint8_t
Typedef documentation
using TrinyxJobs:: WorldQueueHandle = uint32_t
Function documentation
Queue TrinyxJobs:: operator|(Queue a,
Queue b) constexpr
Queue TrinyxJobs:: operator&(Queue a,
Queue b) constexpr
bool TrinyxJobs:: Initialize(const EngineConfig* config)
Initialize queues and spawn worker threads (count from ThreadPinning).
void TrinyxJobs:: Shutdown()
Signal workers to stop and join all threads. Safe to call multiple times.
bool TrinyxJobs:: IsRunning()
Returns true if the job system has been initialized and workers are running. Check before dispatching from code that may outlive the engine (e.g. net threads).
template<ValidJobLambda LAMBDA>
void TrinyxJobs:: Dispatch(LAMBDA lambda,
JobCounter* counter,
Queue queue = Queue::General)
Dispatch a lambda as a job. Increments counter before submission. All Dispatches for a given counter must complete before WaitForCounter.
template<ValidNamedJobLambda LAMBDA>
void TrinyxJobs:: DispatchNamed(const char* name,
LAMBDA lambda,
JobCounter* counter,
Queue queue = Queue::General)
Dispatch a named lambda as a job. Identical to Dispatch but emits a profiler zone with the given name when the job executes. Name must be a string literal (static storage). Lambda captures are limited to 40 bytes (vs. 48 for Dispatch) — the name pointer occupies the remaining 8 bytes of the 48-byte payload.
void TrinyxJobs:: WaitForCounter(JobCounter* counter,
Queue affinity = Queue::All)
Spin until the counter reaches 0, stealing work from all queues while waiting. The calling thread becomes a worker during the wait.
uint32_t TrinyxJobs:: GetWorkerCount()
Number of active worker threads (excludes coordinators).
uint32_t TrinyxJobs:: GetCurrentThreadIndex()
Thread-local index of the current worker (0 = coordinator/non-worker).
WorldQueueHandle TrinyxJobs:: CreateWorldQueue(size_t capacity = 256)
void TrinyxJobs:: DestroyWorldQueue(WorldQueueHandle handle)
void TrinyxJobs:: DrainWorldQueue(WorldQueueHandle handle)
void TrinyxJobs:: SubmitWorldJob(const Job& job,
WorldQueueHandle handle)
Internal — called by Post/Spawn/SpawnAndWait templates.
template<ValidJobLambda LAMBDA>
void TrinyxJobs:: Post(LAMBDA lambda,
WorldQueueHandle handle)
template<ValidJobLambda LAMBDA>
void TrinyxJobs:: Spawn(LAMBDA lambda,
JobCounter* counter,
WorldQueueHandle handle)
template<ValidJobLambda LAMBDA>
void TrinyxJobs:: SpawnAndWait(LAMBDA lambda,
WorldQueueHandle handle)
Variable documentation
static WorldQueueHandle TrinyxJobs:: InvalidWorldQueue constexpr