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

Per-thread control handle for OS-level scheduling operations. More...

#include <thread_control_block.hpp>

Public Member Functions

 thread_control_block ()=default
 
 thread_control_block (thread_control_block const &)=delete
 
auto operator= (thread_control_block const &) -> thread_control_block &=delete
 
 thread_control_block (thread_control_block &&)=delete
 
auto operator= (thread_control_block &&) -> thread_control_block &=delete
 
 ~thread_control_block ()=default
 
auto tid () const noexcept -> native_thread_id
 
auto std_id () const noexcept -> std::thread::id
 
auto set_affinity (native_thread_affinity const &affinity) const -> expected< void, std::error_code >
 
auto set_priority (native_thread_priority priority) const -> expected< void, std::error_code >
 
auto set_nice_value (int nice_value) const -> expected< void, std::error_code >
 
auto get_nice_value () const -> expected< int, 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 set_name (std::string const &name) const -> expected< void, std::error_code >
 

Static Public Member Functions

static auto create_for_current_thread () -> std::shared_ptr< thread_control_block >
 

Friends

class thread_registry_backend
 

Detailed Description

Per-thread control handle for OS-level scheduling operations.

A thread_control_block captures the native thread handle (pthread_t on Linux, a duplicated HANDLE on Windows) at construction time and exposes cross-platform methods to modify the thread's affinity, priority, scheduling policy, and OS-visible name.

Creation
Always use the static factory create_for_current_thread(). It must be called from the thread it will represent, because it snapshots pthread_self() / GetCurrentThread().
Ownership
thread_control_block is intended to be held via std::shared_ptr so that the registry, the owning thread, and any observers can all share the same instance. The static factory already returns a shared_ptr.
Thread safety
  • The object is not copyable and not movable (identity type).
  • All set_* methods are safe to call from any thread - they operate on the stored native handle, not on thread-local state.
  • Concurrent calls to different set_* methods on the same instance are safe (each call is a single OS syscall on the stored handle).
  • The control block is invalidated automatically while its represented thread exits. Later operations return std::errc::no_such_process.
Platform notes
  • Linux: stores pthread_t obtained via pthread_self(). No resource is owned; the handle is valid for the lifetime of the thread.
  • Windows: duplicates the pseudo-handle returned by GetCurrentThread() into a real HANDLE with THREAD_SET_INFORMATION | THREAD_QUERY_INFORMATION rights. The duplicated handle is closed in the destructor.
Caveats

Definition at line 121 of file thread_control_block.hpp.

Constructor & Destructor Documentation

◆ thread_control_block() [1/3]

threadschedule::detail::thread_control_block::thread_control_block ( )
default

◆ thread_control_block() [2/3]

threadschedule::detail::thread_control_block::thread_control_block ( thread_control_block const &  )
delete

◆ thread_control_block() [3/3]

threadschedule::detail::thread_control_block::thread_control_block ( thread_control_block &&  )
delete

◆ ~thread_control_block()

threadschedule::detail::thread_control_block::~thread_control_block ( )
default

Member Function Documentation

◆ configure()

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

◆ create_for_current_thread()

◆ get_nice_value()

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

◆ operator=() [1/2]

auto threadschedule::detail::thread_control_block::operator= ( thread_control_block &&  ) -> thread_control_block &=delete
delete

◆ operator=() [2/2]

auto threadschedule::detail::thread_control_block::operator= ( thread_control_block const &  ) -> thread_control_block &=delete
delete

◆ set_affinity()

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

◆ set_name()

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

Definition at line 235 of file thread_control_block.hpp.

◆ set_nice_value()

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

Definition at line 182 of file thread_control_block.hpp.

◆ set_priority()

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

◆ set_scheduling_policy()

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

Definition at line 208 of file thread_control_block.hpp.

◆ std_id()

auto threadschedule::detail::thread_control_block::std_id ( ) const -> std::thread::id
inlinenoexcept

Definition at line 138 of file thread_control_block.hpp.

◆ tid()

auto threadschedule::detail::thread_control_block::tid ( ) const -> native_thread_id
inlinenoexcept

Definition at line 133 of file thread_control_block.hpp.

Friends And Related Symbol Documentation

◆ thread_registry_backend

friend class thread_registry_backend
friend

Definition at line 327 of file thread_control_block.hpp.


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