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

Lightweight handle for querying and controlling a specific OS thread. More...

#include <thread_backend.hpp>

Public Types

using native_handle_type = pthread_t

Public Member Functions

 thread_info ()
 thread_info (native_thread_id tid)
auto thread_id () const noexcept -> native_thread_id
auto set_name (std::string const &name) const -> expected< void, std::error_code >
auto get_name () const -> expected< std::string, std::error_code >
auto set_priority (native_thread_priority priority) const -> expected< void, std::error_code >
auto set_scheduling_policy (native_scheduling_policy policy, native_thread_priority priority) const -> expected< void, std::error_code >
auto configure (native_scheduling_config const &config) const -> expected< void, std::error_code >
auto configure (native_thread_config const &config) const -> expected< void, std::error_code >
auto set_affinity (native_thread_affinity const &affinity) const -> expected< void, std::error_code >
auto get_affinity () const -> expected< native_thread_affinity, std::error_code >
auto get_policy () const -> std::optional< native_scheduling_policy >
auto get_priority () const -> std::optional< int >

Static Public Member Functions

static auto hardware_concurrency () -> unsigned int
static auto get_thread_id () -> native_thread_id
static auto get_current_policy () -> std::optional< native_scheduling_policy >
static auto get_current_priority () -> std::optional< int >

Detailed Description

Lightweight handle for querying and controlling a specific OS thread.

The default constructor binds to the current thread. The explicit constructor binds to a caller-provided OS thread ID (native_thread_id), allowing callers to act on library-owned background threads or any other live thread in the process.

Provided Queries / Operations
  • hardware_concurrency() - delegates to std::thread::hardware_concurrency().
  • get_thread_id() - returns the OS-level thread ID (Linux TID via syscall(SYS_gettid), Windows thread ID via GetCurrentThreadId()).
  • instance methods provide set_name, get_name, set_priority, set_scheduling_policy, set_affinity, get_affinity, get_policy, and get_priority for the bound thread ID.
  • static get_current_policy() / get_current_priority() remain as compatibility conveniences for the current thread.
Thread Safety
Individual operations are thread-safe and delegate to OS syscalls for the bound thread. Default-constructed instances prefer the captured native thread handle when available; thread_info(native_thread_id) continues to use the caller-provided OS thread ID.

Definition at line 645 of file thread_backend.hpp.

Member Typedef Documentation

◆ native_handle_type

Constructor & Destructor Documentation

◆ thread_info() [1/2]

threadschedule::detail::thread_info::thread_info ( )
inline

Definition at line 654 of file thread_backend.hpp.

References get_thread_id().

Referenced by get_current_policy(), and get_current_priority().

◆ thread_info() [2/2]

threadschedule::detail::thread_info::thread_info ( native_thread_id tid)
inlineexplicit

Definition at line 659 of file thread_backend.hpp.

Member Function Documentation

◆ configure() [1/2]

auto threadschedule::detail::thread_info::configure ( native_scheduling_config const & config) const->expected< void, std::error_code >
inlinenodiscard

◆ configure() [2/2]

auto threadschedule::detail::thread_info::configure ( native_thread_config const & config) const->expected< void, std::error_code >
inlinenodiscard

Definition at line 716 of file thread_backend.hpp.

References threadschedule::detail::configure_thread().

◆ get_affinity()

auto threadschedule::detail::thread_info::get_affinity ( ) const->expected< native_thread_affinity, std::error_code >
inlinenodiscard

◆ get_current_policy()

auto threadschedule::detail::thread_info::get_current_policy ( ) ->std::optional< native_scheduling_policy >
inlinestatic

Definition at line 770 of file thread_backend.hpp.

References thread_info().

◆ get_current_priority()

auto threadschedule::detail::thread_info::get_current_priority ( ) ->std::optional< int >
inlinestatic

Definition at line 776 of file thread_backend.hpp.

References thread_info().

◆ get_name()

auto threadschedule::detail::thread_info::get_name ( ) const->expected< std::string, std::error_code >
inlinenodiscard

◆ get_policy()

auto threadschedule::detail::thread_info::get_policy ( ) const->std::optional< native_scheduling_policy >
inlinenodiscard

◆ get_priority()

auto threadschedule::detail::thread_info::get_priority ( ) const->std::optional< int >
inlinenodiscard

Definition at line 746 of file thread_backend.hpp.

References threadschedule::detail::read_priority().

◆ get_thread_id()

◆ hardware_concurrency()

auto threadschedule::detail::thread_info::hardware_concurrency ( ) ->unsignedint
inlinestatic

Definition at line 754 of file thread_backend.hpp.

◆ set_affinity()

auto threadschedule::detail::thread_info::set_affinity ( native_thread_affinity const & affinity) const->expected< void, std::error_code >
inlinenodiscard

◆ set_name()

auto threadschedule::detail::thread_info::set_name ( std::string const & name) const->expected< void, std::error_code >
inlinenodiscard

◆ set_priority()

auto threadschedule::detail::thread_info::set_priority ( native_thread_priority priority) const->expected< void, std::error_code >
inlinenodiscard

◆ set_scheduling_policy()

auto threadschedule::detail::thread_info::set_scheduling_policy ( native_scheduling_policy policy,
native_thread_priority priority ) const->expected< void, std::error_code >
inlinenodiscard

◆ thread_id()

auto threadschedule::detail::thread_info::thread_id ( ) const->native_thread_id
inlinenodiscardnoexcept

Definition at line 662 of file thread_backend.hpp.


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