|
|
| ThreadRegistry (ThreadRegistry const &)=delete |
|
auto | operator= (ThreadRegistry const &) -> ThreadRegistry &=delete |
| void | register_current_thread (std::string name=std::string(), std::string componentTag=std::string()) |
| void | register_current_thread (std::shared_ptr< ThreadControlBlock > const &controlBlock, std::string name=std::string(), std::string componentTag=std::string()) |
| void | unregister_current_thread () |
| auto | get (Tid tid) const -> std::optional< RegisteredThreadInfo > |
| auto | query () const -> QueryView |
| template<typename Predicate> |
| auto | filter (Predicate &&pred) const -> QueryView |
| auto | count () const -> size_t |
| auto | empty () const -> bool |
| template<typename Fn> |
| void | for_each (Fn &&fn) const |
| template<typename Predicate, typename Fn> |
| void | apply (Predicate &&pred, Fn &&fn) const |
| template<typename Fn> |
| auto | map (Fn &&fn) const -> std::vector< std::invoke_result_t< Fn, RegisteredThreadInfo const & > > |
| template<typename Predicate> |
| auto | find_if (Predicate &&pred) const -> std::optional< RegisteredThreadInfo > |
| template<typename Predicate> |
| auto | any (Predicate &&pred) const -> bool |
| template<typename Predicate> |
| auto | all (Predicate &&pred) const -> bool |
| template<typename Predicate> |
| auto | none (Predicate &&pred) const -> bool |
| auto | take (size_t n) const -> QueryView |
| auto | skip (size_t n) const -> QueryView |
| auto | set_affinity (Tid tid, ThreadAffinity const &affinity) const -> expected< void, std::error_code > |
| auto | set_priority (Tid tid, ThreadPriority priority) const -> expected< void, std::error_code > |
| auto | set_scheduling_policy (Tid tid, SchedulingPolicy policy, ThreadPriority priority) const -> expected< void, std::error_code > |
| auto | set_name (Tid tid, std::string const &name) const -> expected< void, std::error_code > |
| void | set_on_register (std::function< void(RegisteredThreadInfo const &)> cb) |
| void | set_on_unregister (std::function< void(RegisteredThreadInfo const &)> cb) |
Central registry of threads indexed by OS-level thread ID (Tid).
ThreadRegistry maintains a map of currently registered threads together with their metadata and optional ThreadControlBlock handles. It provides a functional-style query API (via QueryView) and convenience methods that delegate scheduling operations to each thread's control block.
- Thread safety
- All public methods are thread-safe. Internal state is protected by a
std::shared_mutex: mutating operations (register, unregister, set callbacks) acquire a unique lock, while read-only operations (get, query, set_affinity, etc.) acquire a shared lock.
- Copyability / movability
- Not copyable (copy constructor and assignment are deleted).
- Not movable (implicitly deleted because copy operations are deleted and the class holds a
std::shared_mutex).
- Registration semantics
- register_current_thread() must be called from the thread being registered. Duplicate registration of the same TID is silently ignored (the first registration wins).
- unregister_current_thread() removes the calling thread's entry and marks its
alive flag as false in the snapshot passed to the callback.
- Callbacks
- The optional
onRegister / onUnregister callbacks are invoked with the lock released to avoid deadlock if the callback itself interacts with the registry. The callback receives a copy of the RegisteredThreadInfo.
- Querying
- query() returns a QueryView holding a snapshot of the registry at the moment of the call. Subsequent changes to the registry (new registrations, unregistrations) are not reflected in an existing QueryView.
- Scheduling helpers
- set_affinity(), set_priority(), set_scheduling_policy(), and set_name() look up the ThreadControlBlock for the given TID under a shared lock and delegate to the control block. Returns
std::errc::no_such_process if the TID is not registered or has no control block.
Definition at line 336 of file thread_registry.hpp.