ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag > Class Template Reference

Polymorphic base providing common thread management operations. More...

#include <thread_backend.hpp>

Inheritance diagram for threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >:
[legend]
Collaboration diagram for threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >:
[legend]

Public Types

using native_handle_type = typename ThreadType::native_handle_type
 
using id = typename ThreadType::id
 

Public Member Functions

 basic_thread_backend ()=default
 
 basic_thread_backend (ThreadType &t)
 
 basic_thread_backend (ThreadType &t, native_thread_id tid)
 
virtual ~basic_thread_backend ()=default
 
void join ()
 
void detach ()
 
auto joinable () const noexcept -> bool
 
auto get_id () const noexcept -> id
 
auto native_handle () noexcept -> native_handle_type
 
auto set_name (std::string const &name) -> expected< void, std::error_code >
 
auto get_name () const -> expected< std::string, std::error_code >
 
auto set_priority (native_thread_priority priority) -> expected< void, std::error_code >
 
auto set_scheduling_policy (native_scheduling_policy policy, native_thread_priority priority) -> expected< void, std::error_code >
 
auto configure (native_scheduling_config const &config) -> expected< void, std::error_code >
 
auto set_nice_value (int nice_value) -> expected< void, std::error_code >
 
auto get_nice_value () const -> expected< int, std::error_code >
 
auto configure (native_thread_config const &config) -> expected< void, std::error_code >
 
auto set_affinity (native_thread_affinity const &affinity) -> expected< void, std::error_code >
 
auto get_affinity () const -> expected< native_thread_affinity, std::error_code >
 
auto native_id () const noexcept -> native_thread_id
 

Protected Member Functions

void set_native_id (native_thread_id tid) noexcept
 

Static Protected Member Functions

static auto no_such_thread () -> unexpected< std::error_code >
 

Protected Attributes

native_thread_id native_id_ {}
 

Detailed Description

template<typename ThreadType, typename OwnershipTag = detail::owning_tag>
class threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >

Polymorphic base providing common thread management operations.

Template Parameters
ThreadTypeThe underlying thread type (std::thread or std::jthread).
OwnershipTagdetail::owning_tag (default) or detail::non_owning_tag.

Provides a uniform interface for join, detach, naming, priority, affinity, scheduling policy, and nice-value control on top of any standard thread type. Derived classes (thread_backend and thread_view_backend) customize ownership semantics while inheriting all of these operations.

Virtual Destructor
Has a virtual destructor so it can be used as a polymorphic base.
join() / detach()
Both are safe to call even if the thread is not joinable (they check first).
set_name()
  • Linux: uses pthread_setname_np; names are limited to 15 characters (returns errc::invalid_argument if exceeded).
  • Windows: dynamically loads SetThreadDescription from Kernel32.dll or KernelBase.dll. Names may be longer. Returns errc::function_not_supported if the API is unavailable (pre-Windows 10 1607).
get_name()
Returns expected<std::string, std::error_code> so unavailable APIs, invalid handles, OS failures, and UTF conversion failures remain diagnosable.
set_priority()
Applies the regular portable priority model. On Linux this selects SCHED_OTHER and updates the thread's nice value. On Windows it maps to SetThreadPriority constants.
set_scheduling_policy()
Linux-specific concept; on Windows this falls back to set_priority().
set_affinity()
  • Linux: pthread_setaffinity_np with cpu_set_t.
  • Windows: prefers SetThreadGroupAffinity (multi-processor-group aware) and falls back to SetThreadAffinityMask on single-group systems.
set_nice_value() / get_nice_value()
Per-thread operation. On Linux, calls setpriority(PRIO_PROCESS, tid, ...) using the captured kernel TID. On Windows, maps to SetThreadPriority / GetThreadPriority without changing the process priority class.
Return Values
All set_* methods return expected<void, std::error_code>. Always check the return value; failures are silent unless inspected.
Thread Safety
Individual method calls are safe if the underlying OS call is safe, but concurrent mutation of the same wrapper from multiple threads is not synchronized internally.

Definition at line 255 of file thread_backend.hpp.

Member Typedef Documentation

◆ id

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
using threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::id = typename ThreadType::id

Definition at line 259 of file thread_backend.hpp.

◆ native_handle_type

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
using threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::native_handle_type = typename ThreadType::native_handle_type

Definition at line 258 of file thread_backend.hpp.

Constructor & Destructor Documentation

◆ basic_thread_backend() [1/3]

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::basic_thread_backend ( )
default

◆ basic_thread_backend() [2/3]

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::basic_thread_backend ( ThreadType &  t)
inlineexplicit

Definition at line 262 of file thread_backend.hpp.

◆ basic_thread_backend() [3/3]

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::basic_thread_backend ( ThreadType &  t,
native_thread_id  tid 
)
inline

Definition at line 263 of file thread_backend.hpp.

◆ ~basic_thread_backend()

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
virtual threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::~basic_thread_backend ( )
virtualdefault

Member Function Documentation

◆ configure() [1/2]

◆ configure() [2/2]

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
auto threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::configure ( native_thread_config const &  config) -> expected<void, std::error_code>
inline

Definition at line 377 of file thread_backend.hpp.

References threadschedule::detail::configure_thread().

◆ detach()

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
void threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::detach ( )
inline

◆ get_affinity()

◆ get_id()

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
auto threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::get_id ( ) const -> id
inlinenoexcept

Definition at line 296 of file thread_backend.hpp.

Referenced by threadschedule::thread::get_id().

◆ get_name()

◆ get_nice_value()

◆ join()

◆ joinable()

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
auto threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::joinable ( ) const -> bool
inlinenoexcept

◆ native_handle()

◆ native_id()

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
auto threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::native_id ( ) const -> native_thread_id
inlinenoexcept

◆ no_such_thread()

◆ set_affinity()

◆ set_name()

◆ set_native_id()

template<typename ThreadType , typename OwnershipTag = detail::owning_tag>
void threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::set_native_id ( native_thread_id  tid)
inlineprotectednoexcept

◆ set_nice_value()

◆ set_priority()

◆ set_scheduling_policy()

Member Data Documentation

◆ native_id_


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