ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::detail::thread_registry_backend Class Reference

Central registry of threads indexed by OS-level thread ID (native_thread_id). More...

#include <thread_registry_backend.hpp>

Inheritance diagram for threadschedule::detail::thread_registry_backend:
[legend]
Collaboration diagram for threadschedule::detail::thread_registry_backend:
[legend]

Classes

class  query_view
 Lazy, functional-style query/filter view over a snapshot of registered threads. More...
 

Public Member Functions

 thread_registry_backend ()=default
 
 ~thread_registry_backend ()
 
 thread_registry_backend (thread_registry_backend const &)=delete
 
auto operator= (thread_registry_backend const &) -> thread_registry_backend &=delete
 
void register_current_thread (std::string name=std::string(), std::string component=std::string())
 
void register_current_thread (std::shared_ptr< thread_control_block > const &control_block, std::string name=std::string(), std::string component=std::string())
 
void unregister_current_thread ()
 
auto get (native_thread_id tid) const -> std::optional< registered_thread_info_backend >
 
auto query () const -> query_view
 
auto set_affinity (native_thread_id tid, native_thread_affinity const &affinity) const -> expected< void, std::error_code >
 
auto set_priority (native_thread_id tid, native_thread_priority priority) const -> expected< void, std::error_code >
 
auto set_nice_value (native_thread_id tid, int nice_value) const -> expected< void, std::error_code >
 
auto get_nice_value (native_thread_id tid) const -> expected< int, std::error_code >
 
auto set_scheduling_policy (native_thread_id tid, native_scheduling_policy policy, native_thread_priority priority) const -> expected< void, std::error_code >
 
auto configure (native_thread_id tid, native_scheduling_config const &config) const -> expected< void, std::error_code >
 
auto configure (native_thread_id tid, native_thread_config const &config) const -> expected< void, std::error_code >
 
auto set_name (native_thread_id tid, std::string const &name) const -> expected< void, std::error_code >
 
void update_registered_name (native_thread_id tid, std::string const &name)
 
void set_on_register (registry_callback cb)
 
template<typename Callback , std::enable_if_t<!std::is_same_v< std::decay_t< Callback >, registry_callback >, int > = 0>
void set_on_register (Callback &&cb)
 
void set_on_unregister (registry_callback cb)
 
template<typename Callback , std::enable_if_t<!std::is_same_v< std::decay_t< Callback >, registry_callback >, int > = 0>
void set_on_unregister (Callback &&cb)
 
- Public Member Functions inherited from threadschedule::detail::query_facade_mixin< thread_registry_backend >
auto filter (Predicate &&pred) const
 
auto count () const -> size_t
 
auto empty () const -> bool
 
void for_each (Fn &&fn) const
 
void apply (Predicate &&pred, Fn &&fn) const
 
auto map (Fn &&fn) const -> std::vector< std::invoke_result_t< Fn, registered_thread_info_backend const & > >
 
auto find_if (Predicate &&pred) const -> std::optional< registered_thread_info_backend >
 
auto any (Predicate &&pred) const -> bool
 
auto all (Predicate &&pred) const -> bool
 
auto none (Predicate &&pred) const -> bool
 
auto take (size_t n) const
 
auto skip (size_t n) const
 

Friends

class registration_guard_backend
 
class ::threadschedule::auto_register_current_thread
 

Detailed Description

Central registry of threads indexed by OS-level thread ID (native_thread_id).

thread_registry_backend maintains a map of currently registered threads together with their metadata and optional thread_control_block handles. It provides a functional-style query API (via query_view) 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 registered_thread_info_backend.
Querying
query() returns a query_view 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 query_view. The same functional-style helpers (filter, map, for_each, etc.) are inherited from detail::query_facade_mixin.
Scheduling helpers
set_affinity(), set_priority(), set_scheduling_policy(), and set_name() look up the thread_control_block 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 79 of file thread_registry_backend.hpp.

Constructor & Destructor Documentation

◆ thread_registry_backend() [1/2]

threadschedule::detail::thread_registry_backend::thread_registry_backend ( )
default

◆ ~thread_registry_backend()

threadschedule::detail::thread_registry_backend::~thread_registry_backend ( )
inline

◆ thread_registry_backend() [2/2]

threadschedule::detail::thread_registry_backend::thread_registry_backend ( thread_registry_backend const )
delete

Member Function Documentation

◆ configure() [1/2]

auto threadschedule::detail::thread_registry_backend::configure ( native_thread_id  tid,
native_scheduling_config const config 
) const -> expected<void, std::error_code>
inline

◆ configure() [2/2]

auto threadschedule::detail::thread_registry_backend::configure ( native_thread_id  tid,
native_thread_config const config 
) const -> expected<void, std::error_code>
inline

◆ get()

auto threadschedule::detail::thread_registry_backend::get ( native_thread_id  tid) const -> std::optional<registered_thread_info_backend>
inline

◆ get_nice_value()

auto threadschedule::detail::thread_registry_backend::get_nice_value ( native_thread_id  tid) const -> expected<int, std::error_code>
inline

◆ operator=()

◆ query()

auto threadschedule::detail::thread_registry_backend::query ( ) const -> query_view
inline

◆ register_current_thread() [1/2]

void threadschedule::detail::thread_registry_backend::register_current_thread ( std::shared_ptr< thread_control_block > const control_block,
std::string  name = std::string(),
std::string  component = std::string() 
)
inline

◆ register_current_thread() [2/2]

void threadschedule::detail::thread_registry_backend::register_current_thread ( std::string  name = std::string(),
std::string  component = std::string() 
)
inline

◆ set_affinity()

auto threadschedule::detail::thread_registry_backend::set_affinity ( native_thread_id  tid,
native_thread_affinity const affinity 
) const -> expected<void, std::error_code>
inline

◆ set_name()

auto threadschedule::detail::thread_registry_backend::set_name ( native_thread_id  tid,
std::string const name 
) const -> expected<void, std::error_code>
inline

◆ set_nice_value()

auto threadschedule::detail::thread_registry_backend::set_nice_value ( native_thread_id  tid,
int  nice_value 
) const -> expected<void, std::error_code>
inline

◆ set_on_register() [1/2]

template<typename Callback , std::enable_if_t<!std::is_same_v< std::decay_t< Callback >, registry_callback >, int > = 0>
void threadschedule::detail::thread_registry_backend::set_on_register ( Callback &&  cb)
inline

◆ set_on_register() [2/2]

void threadschedule::detail::thread_registry_backend::set_on_register ( registry_callback  cb)
inline

◆ set_on_unregister() [1/2]

template<typename Callback , std::enable_if_t<!std::is_same_v< std::decay_t< Callback >, registry_callback >, int > = 0>
void threadschedule::detail::thread_registry_backend::set_on_unregister ( Callback &&  cb)
inline

◆ set_on_unregister() [2/2]

void threadschedule::detail::thread_registry_backend::set_on_unregister ( registry_callback  cb)
inline

◆ set_priority()

auto threadschedule::detail::thread_registry_backend::set_priority ( native_thread_id  tid,
native_thread_priority  priority 
) const -> expected<void, std::error_code>
inline

◆ set_scheduling_policy()

auto threadschedule::detail::thread_registry_backend::set_scheduling_policy ( native_thread_id  tid,
native_scheduling_policy  policy,
native_thread_priority  priority 
) const -> expected<void, std::error_code>
inline

◆ unregister_current_thread()

void threadschedule::detail::thread_registry_backend::unregister_current_thread ( )
inline

◆ update_registered_name()

void threadschedule::detail::thread_registry_backend::update_registered_name ( native_thread_id  tid,
std::string const name 
)
inline

Friends And Related Symbol Documentation

◆ ::threadschedule::auto_register_current_thread

◆ registration_guard_backend


The documentation for this class was generated from the following file: