Skip to main content

chronon::observe::ThreadContextManager

Singleton managing per-thread observability contexts. More...

#include <ThreadContextManager.hpp>

Public Functions

Name
boolwakeBackend()
Safe to call from any producer thread.
uint64_ttotalDroppedCount() const
voidsetQueueCapacity(size_t capacity)
PRECONDITION: must be called before any thread calls getContext().
voidsetBackpressurePolicy(BackpressurePolicy policy)
PRECONDITION: must be called before any thread calls getContext().
voidsetBackpressurePolicy(ObservationChannel ch, BackpressurePolicy policy)
voidsetBackpressureMaxSpins(uint32_t max_spins)
voidsetBackpressureMaxSpins(ObservationChannel ch, uint32_t max_spins)
voidsetBackendWakeup(void(*)(void *) fn, void * ctx)
Register a callback the backend uses to be woken by producers.
size_tqueueCapacity() const
boolisInitialized() const
ThreadContextManager &instance()
ThreadContext *getContext()
Get or create the calling thread's context.
template <typename Fn >
void
forEachContext(Fn && fn)
voidflushAll()
BackpressurePolicybackpressurePolicy() const
BackpressurePolicybackpressurePolicy(ObservationChannel ch) const
uint32_tbackpressureMaxSpins() const
uint32_tbackpressureMaxSpins(ObservationChannel ch) const
size_tallocatedContextCount() const
Pool high-water allocation, bounded by MAX_THREADS and reused after drain.
size_tactiveThreadCount() const

Public Attributes

Name
size_tMAX_THREADS

Detailed Description

class chronon::observe::ThreadContextManager;

Singleton managing per-thread observability contexts.

Bounded, reusable context pool with a thread-local pointer cache. Queue addresses and IDs stay stable for backend readers. Only producer handoff and backend wakeups take locks; event writes and consumer scans do not.

Public Functions Documentation

function wakeBackend

inline bool wakeBackend()

Safe to call from any producer thread.

function totalDroppedCount

inline uint64_t totalDroppedCount() const

function setQueueCapacity

inline void setQueueCapacity(
size_t capacity
)

PRECONDITION: must be called before any thread calls getContext().

function setBackpressurePolicy

inline void setBackpressurePolicy(
BackpressurePolicy policy
)

PRECONDITION: must be called before any thread calls getContext().

function setBackpressurePolicy

inline void setBackpressurePolicy(
ObservationChannel ch,
BackpressurePolicy policy
)

function setBackpressureMaxSpins

inline void setBackpressureMaxSpins(
uint32_t max_spins
)

function setBackpressureMaxSpins

inline void setBackpressureMaxSpins(
ObservationChannel ch,
uint32_t max_spins
)

function setBackendWakeup

inline void setBackendWakeup(
void(*)(void *) fn,
void * ctx
)

Register a callback the backend uses to be woken by producers.

Removing/replacing the callback waits for in-flight wakeups, including exiting producers, before the backend can be destroyed. The callback must not recursively change or invoke this notification registration.

function queueCapacity

inline size_t queueCapacity() const

function isInitialized

inline bool isInitialized() const

function instance

static inline ThreadContextManager & instance()

function getContext

inline ThreadContext * getContext()

Get or create the calling thread's context.

Return: Thread context, or nullptr if all MAX_THREADS slots have a live producer or unconsumed records from an exited producer, or the calling thread has already retired its producer during TLS destruction. The producer pointer is valid for the calling thread's lifetime only.

function forEachContext

template <typename Fn >
inline void forEachContext(
Fn && fn
)

Visits allocated queues, including exited producers' unread records. Addresses remain stable across producer handoff. Queue reads still require a single consumer, which must commit reads before reuse.

function flushAll

inline void flushAll()

Event writers must be quiescent. Registration and TLS retirement may still run: serialize their writer-state handoff with this final flush.

function backpressurePolicy

inline BackpressurePolicy backpressurePolicy() const

function backpressurePolicy

inline BackpressurePolicy backpressurePolicy(
ObservationChannel ch
) const

function backpressureMaxSpins

inline uint32_t backpressureMaxSpins() const

function backpressureMaxSpins

inline uint32_t backpressureMaxSpins(
ObservationChannel ch
) const

function allocatedContextCount

inline size_t allocatedContextCount() const

Pool high-water allocation, bounded by MAX_THREADS and reused after drain.

function activeThreadCount

inline size_t activeThreadCount() const

Public Attributes Documentation

variable MAX_THREADS

static size_t MAX_THREADS = 64;

Updated on 2026-09-20 at 14:23:39 +0000