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

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

#include <thread_wrapper.hpp>

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

Public Types

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

Public Member Functions

 BaseThreadWrapper (ThreadType &t)
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 -> std::optional< std::string >
auto set_priority (ThreadPriority priority) -> expected< void, std::error_code >
auto set_scheduling_policy (SchedulingPolicy policy, ThreadPriority priority) -> expected< void, std::error_code >
auto set_affinity (ThreadAffinity const &affinity) -> expected< void, std::error_code >
auto get_affinity () const -> std::optional< ThreadAffinity >

Static Public Member Functions

static auto set_nice_value (int nice_value) -> bool
static auto get_nice_value () -> std::optional< int >

Detailed Description

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
class threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >

Polymorphic base providing common thread management operations.

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

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 (ThreadWrapper, JThreadWrapper, and their View counterparts) 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. Names may be longer. Returns errc::function_not_supported if the API is unavailable (pre-Windows 10 1607).
set_priority()
Maps through SchedulerParams::create_for_policy(). On Linux, uses pthread_setschedparam and may require CAP_SYS_NICE or root privileges for real-time policies. On Windows, 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()
Process-level operation - affects all threads in the process. On Linux calls setpriority(PRIO_PROCESS, ...). On Windows maps to SetPriorityClass / GetPriorityClass.
Return Values
All set_* methods (except set_nice_value) 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 163 of file thread_wrapper.hpp.

Member Typedef Documentation

◆ id

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
using threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::id = typename ThreadType::id

Definition at line 167 of file thread_wrapper.hpp.

◆ native_handle_type

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
using threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::native_handle_type = typename ThreadType::native_handle_type

Definition at line 166 of file thread_wrapper.hpp.

Constructor & Destructor Documentation

◆ BaseThreadWrapper()

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

Definition at line 170 of file thread_wrapper.hpp.

Member Function Documentation

◆ detach()

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

Definition at line 184 of file thread_wrapper.hpp.

◆ get_affinity()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::get_affinity ( ) const -> std::optional<ThreadAffinity>
inlinenodiscard

Definition at line 396 of file thread_wrapper.hpp.

◆ get_id()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::get_id ( ) const -> id
inlinenodiscardnoexcept

Definition at line 196 of file thread_wrapper.hpp.

◆ get_name()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::get_name ( ) const -> std::optional<std::string>
inlinenodiscard

Definition at line 239 of file thread_wrapper.hpp.

◆ get_nice_value()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::get_nice_value ( ) -> std::optional<int>
inlinestatic

Definition at line 473 of file thread_wrapper.hpp.

◆ join()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
void threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::join ( )
inline

Definition at line 176 of file thread_wrapper.hpp.

◆ joinable()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::joinable ( ) const -> bool
inlinenodiscardnoexcept

Definition at line 192 of file thread_wrapper.hpp.

◆ native_handle()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::native_handle ( ) -> native_handle_type
inlinenodiscardnoexcept

Definition at line 200 of file thread_wrapper.hpp.

◆ set_affinity()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::set_affinity ( ThreadAffinity const & affinity) -> expected<void, std::error_code>
inlinenodiscard

Definition at line 362 of file thread_wrapper.hpp.

◆ set_name()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::set_name ( std::string const & name) -> expected<void, std::error_code>
inlinenodiscard

Definition at line 206 of file thread_wrapper.hpp.

◆ set_nice_value()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::set_nice_value ( int nice_value) -> bool
inlinestatic

Definition at line 441 of file thread_wrapper.hpp.

◆ set_priority()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::set_priority ( ThreadPriority priority) -> expected<void, std::error_code>
inlinenodiscard

Definition at line 280 of file thread_wrapper.hpp.

◆ set_scheduling_policy()

template<typename ThreadType, typename OwnershipTag = detail::OwningTag>
auto threadschedule::BaseThreadWrapper< ThreadType, OwnershipTag >::set_scheduling_policy ( SchedulingPolicy policy,
ThreadPriority priority ) -> expected<void, std::error_code>
inlinenodiscard

Definition at line 339 of file thread_wrapper.hpp.


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