chronon::observe::ThreadContextManager
Singleton managing per-thread observability contexts. More...
#include <ThreadContextManager.hpp>
Public Functions
| Name | |
|---|---|
| bool | wakeBackend() Safe to call from any producer thread. |
| uint64_t | totalDroppedCount() const |
| void | setQueueCapacity(size_t capacity) PRECONDITION: must be called before any thread calls getContext(). |
| void | setBackpressurePolicy(BackpressurePolicy policy) PRECONDITION: must be called before any thread calls getContext(). |
| void | setBackpressurePolicy(ObservationChannel ch, BackpressurePolicy policy) |
| void | setBackpressureMaxSpins(uint32_t max_spins) |
| void | setBackpressureMaxSpins(ObservationChannel ch, uint32_t max_spins) |
| void | setBackendWakeup(void(*)(void *) fn, void * ctx) Register a callback the backend uses to be woken by producers. |
| size_t | queueCapacity() const |
| bool | isInitialized() const |
| ThreadContextManager & | instance() |
| ThreadContext * | getContext() Get or create the calling thread's context. |
| template <typename Fn > void | forEachContext(Fn && fn) |
| void | flushAll() |
| BackpressurePolicy | backpressurePolicy() const |
| BackpressurePolicy | backpressurePolicy(ObservationChannel ch) const |
| uint32_t | backpressureMaxSpins() const |
| uint32_t | backpressureMaxSpins(ObservationChannel ch) const |
| size_t | allocatedContextCount() const Pool high-water allocation, bounded by MAX_THREADS and reused after drain. |
| size_t | activeThreadCount() const |
Public Attributes
| Name | |
|---|---|
| size_t | MAX_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