ThreadSchedule 2.2.0
Modern C++ thread management library
Loading...
Searching...
No Matches

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

#include <thread_wrapper.hpp>

Public Types

using native_handle_type = pthread_t

Public Member Functions

 ThreadInfo ()
 ThreadInfo (Tid tid)
auto thread_id () const noexcept -> Tid
auto set_name (std::string const &name) const -> expected< void, std::error_code >
auto get_name () const -> std::optional< std::string >
auto set_priority (ThreadPriority priority) const -> expected< void, std::error_code >
auto set_scheduling_policy (SchedulingPolicy policy, ThreadPriority priority) const -> expected< void, std::error_code >
auto set_affinity (ThreadAffinity const &affinity) const -> expected< void, std::error_code >
auto get_affinity () const -> std::optional< ThreadAffinity >
auto get_policy () const -> std::optional< SchedulingPolicy >
auto get_priority () const -> std::optional< int >

Static Public Member Functions

static auto hardware_concurrency () -> unsigned int
static auto get_thread_id () -> Tid
static auto get_current_policy () -> std::optional< SchedulingPolicy >
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 (Tid), 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; ThreadInfo(Tid) continues to use the caller-provided OS thread ID.

Definition at line 826 of file thread_wrapper.hpp.

Member Typedef Documentation

◆ native_handle_type

Definition at line 832 of file thread_wrapper.hpp.

Constructor & Destructor Documentation

◆ ThreadInfo() [1/2]

threadschedule::ThreadInfo::ThreadInfo ( )
inline

Definition at line 835 of file thread_wrapper.hpp.

References get_thread_id().

Referenced by get_current_policy(), and get_current_priority().

◆ ThreadInfo() [2/2]

threadschedule::ThreadInfo::ThreadInfo ( Tid tid)
inlineexplicit

Definition at line 840 of file thread_wrapper.hpp.

Member Function Documentation

◆ get_affinity()

auto threadschedule::ThreadInfo::get_affinity ( ) const -> std::optional<ThreadAffinity>
inlinenodiscard

Definition at line 885 of file thread_wrapper.hpp.

References threadschedule::detail::read_affinity().

◆ get_current_policy()

auto threadschedule::ThreadInfo::get_current_policy ( ) -> std::optional<SchedulingPolicy>
inlinestatic

Definition at line 920 of file thread_wrapper.hpp.

References ThreadInfo().

◆ get_current_priority()

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

Definition at line 925 of file thread_wrapper.hpp.

References ThreadInfo().

◆ get_name()

auto threadschedule::ThreadInfo::get_name ( ) const -> std::optional<std::string>
inlinenodiscard

Definition at line 856 of file thread_wrapper.hpp.

References threadschedule::detail::read_name().

◆ get_policy()

auto threadschedule::ThreadInfo::get_policy ( ) const -> std::optional<SchedulingPolicy>
inlinenodiscard

◆ get_priority()

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

Definition at line 899 of file thread_wrapper.hpp.

References threadschedule::detail::read_priority().

◆ get_thread_id()

◆ hardware_concurrency()

auto threadschedule::ThreadInfo::hardware_concurrency ( ) -> unsigned int
inlinestatic

Definition at line 906 of file thread_wrapper.hpp.

◆ set_affinity()

auto threadschedule::ThreadInfo::set_affinity ( ThreadAffinity const & affinity) const -> expected<void, std::error_code>
inlinenodiscard

Definition at line 878 of file thread_wrapper.hpp.

References threadschedule::detail::apply_affinity().

◆ set_name()

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

◆ set_priority()

auto threadschedule::ThreadInfo::set_priority ( ThreadPriority priority) const -> expected<void, std::error_code>
inlinenodiscard

Definition at line 863 of file thread_wrapper.hpp.

References threadschedule::detail::apply_priority().

◆ set_scheduling_policy()

auto threadschedule::ThreadInfo::set_scheduling_policy ( SchedulingPolicy policy,
ThreadPriority priority ) const -> expected<void, std::error_code>
inlinenodiscard

◆ thread_id()

auto threadschedule::ThreadInfo::thread_id ( ) const -> Tid
inlinenodiscardnoexcept

Definition at line 844 of file thread_wrapper.hpp.


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