TrinyxThreading namespace

TrinyxThreading — Core-aware thread pinning.

Call Initialize() once at startup to scan the CPU topology. Then use PinThread() to assign threads to cores in priority order: physical cores first (non-SMT), then SMT siblings. Core 0 is skipped (reserved for OS/interrupts).

The four coordinator threads (Sentinel, Brain, Encoder, NetThread) each get a dedicated physical core. Remaining cores form the worker pool. On CPUs with fewer than 5 cores, Network shares with Sentinel.

Functions

void Initialize()
void PinThread(std::thread& t)
void PinCurrentThread(uint32_t coreId)
Pin the calling thread to a specific core (e.g. for the main/Sentinel thread).
auto GetPhysicalCoreCount() -> uint32_t
Number of physical (processor) cores detected.
auto GetLogicalCoreCount() -> uint32_t
Number of logical cores detected (physical + SMT).
auto GetWorkerThreadCapacity() -> uint32_t
auto GetIdealCore(CoreAffinity affinity) -> uint32_t
auto HasSMT() -> bool
Whether the CPU has SMT (hyperthreading) enabled.
void SetPinningEnabled(bool enabled)
auto IsPinningEnabled() -> bool

Function documentation

void TrinyxThreading::Initialize()

Scan CPU topology and build the core assignment list. Must be called once before any PinThread() calls.

void TrinyxThreading::PinThread(std::thread& t)

Pin the given thread to the next best available core. Assigns physical cores before SMT siblings. Thread-safe.

uint32_t TrinyxThreading::GetWorkerThreadCapacity()

How many cores are available for the worker pool (logical cores minus the 3 reserved coordinator cores).

uint32_t TrinyxThreading::GetIdealCore(CoreAffinity affinity)

Return the ideal core for the requested affinity based on capacity and SMT.

void TrinyxThreading::SetPinningEnabled(bool enabled)

Enable or disable thread pinning globally. Disable in PIE/editor builds where multiple worlds oversubscribe available cores. Must be called before any PinThread() or PinCurrentThread() calls take effect. Default: enabled. Set false before starting threads to make all pin calls no-ops.