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

Owning thread wrapper with result-based lifecycle/configuration API. More...

#include <thread.hpp>

Public Member Functions

 thread ()=default
 Construct an empty, non-joinable thread object.
 
 thread (std::thread &&value) noexcept
 Take ownership of an existing std::thread.
 
template<typename F , typename... Args, std::enable_if_t< !std::is_same_v< std::decay_t< F >, thread > &&!std::is_same_v< std::decay_t< F >, thread_config >, int > = 0>
 thread (F &&function, Args &&... args)
 Start a thread from callable and arguments.
 
template<typename F , typename... Args>
 thread (thread_config const &config, F &&function, Args &&... args)
 Start a thread and apply thread_config before user code runs.
 
 thread (thread &&) noexcept=default
 
auto operator= (thread &&) noexcept -> thread &=default
 
 thread (thread const &)=delete
 
auto operator= (thread const &) -> thread &=delete
 
auto join () -> result< void >
 Join the thread.
 
void join_or_throw ()
 Throwing counterpart to join.
 
auto detach () -> result< void >
 Detach the thread.
 
void detach_or_throw ()
 Throwing counterpart to detach.
 
auto joinable () const noexcept -> bool
 Return whether the thread object owns a running thread.
 
auto get_id () const noexcept -> std::thread::id
 Return std::thread id of the owned thread.
 
auto configure (thread_config const &config) -> result< void >
 Apply a full portable thread configuration to the running thread.
 
auto set_priority (priority_level level) -> result< void >
 Set portable priority preset.
 
auto set_nice (nice_value value) -> result< void >
 Set explicit nice value.
 
auto get_priority () const -> result< priority_level >
 Query current portable priority preset.
 
auto get_nice () const -> result< nice_value >
 Query current nice value.
 
auto set_name (std::string const &name) -> result< void >
 Set thread name.
 
auto get_name () const -> result< std::string >
 Query thread name if supported by platform/backend.
 
auto set_affinity (thread_affinity const &affinity) -> result< void >
 Apply CPU affinity set.
 
auto get_affinity () const -> result< thread_affinity >
 Query current CPU affinity.
 
auto release () noexcept -> std::thread
 Release ownership and return underlying std::thread.
 

Static Public Member Functions

template<typename F , typename... Args>
static auto create (F &&function, Args &&... args) -> std::enable_if_t<!std::is_same_v< std::decay_t< F >, thread_config >, result< thread > >
 Create thread without throwing.
 
template<typename F , typename... Args>
static auto create (thread_config const &config, F &&function, Args &&... args) -> result< thread >
 Create configured thread without throwing.
 
static auto hardware_concurrency () noexcept -> unsigned
 Forward std::thread::hardware_concurrency().
 

Friends

struct detail::native_thread_access
 
class thread_view
 

Detailed Description

Owning thread wrapper with result-based lifecycle/configuration API.

Definition at line 28 of file thread.hpp.

Constructor & Destructor Documentation

◆ thread() [1/6]

threadschedule::thread::thread ( )
default

Construct an empty, non-joinable thread object.

Referenced by create(), and create().

◆ thread() [2/6]

threadschedule::thread::thread ( std::thread &&  value)
inlineexplicitnoexcept

Take ownership of an existing std::thread.

Note
On Linux, nice control reports operation_not_supported because an external thread's kernel TID cannot be recovered portably.

Definition at line 39 of file thread.hpp.

◆ thread() [3/6]

template<typename F , typename... Args, std::enable_if_t< !std::is_same_v< std::decay_t< F >, thread > &&!std::is_same_v< std::decay_t< F >, thread_config >, int > = 0>
threadschedule::thread::thread ( F &&  function,
Args &&...  args 
)
inlineexplicit

Start a thread from callable and arguments.

Parameters
functionCallable entry point.
argsArguments forwarded to function.

Definition at line 48 of file thread.hpp.

◆ thread() [4/6]

template<typename F , typename... Args>
threadschedule::thread::thread ( thread_config const &  config,
F &&  function,
Args &&...  args 
)
inline

Start a thread and apply thread_config before user code runs.

Parameters
configPortable thread configuration.
functionCallable entry point.
argsArguments forwarded to function.

Definition at line 59 of file thread.hpp.

◆ thread() [5/6]

threadschedule::thread::thread ( thread &&  )
defaultnoexcept

◆ thread() [6/6]

threadschedule::thread::thread ( thread const &  )
delete

Member Function Documentation

◆ configure()

auto threadschedule::thread::configure ( thread_config const &  config) -> result<void>
inline

Apply a full portable thread configuration to the running thread.

Definition at line 148 of file thread.hpp.

Referenced by threadschedule::advanced::chaos_controller::configure_thread(), and threadschedule::detail::configure_thread().

◆ create() [1/2]

template<typename F , typename... Args>
static auto threadschedule::thread::create ( F &&  function,
Args &&...  args 
) -> std::enable_if_t<!std::is_same_v<std::decay_t<F>, thread_config>, result<thread>>
inlinestatic

Create thread without throwing.

Parameters
functionCallable entry point.
argsArguments forwarded to function.

Definition at line 76 of file thread.hpp.

References thread(), and threadschedule::detail::try_result().

◆ create() [2/2]

template<typename F , typename... Args>
static auto threadschedule::thread::create ( thread_config const &  config,
F &&  function,
Args &&...  args 
) -> result<thread>
inlinestatic

Create configured thread without throwing.

Parameters
configPortable thread configuration.
functionCallable entry point.
argsArguments forwarded to function.

Definition at line 91 of file thread.hpp.

References thread(), and threadschedule::detail::try_result().

◆ detach()

auto threadschedule::thread::detach ( ) -> result<void>
inline

Detach the thread.

Definition at line 113 of file thread.hpp.

◆ detach_or_throw()

void threadschedule::thread::detach_or_throw ( )
inline

Throwing counterpart to detach.

Definition at line 120 of file thread.hpp.

◆ get_affinity()

auto threadschedule::thread::get_affinity ( ) const -> result<thread_affinity>
inline

Query current CPU affinity.

Definition at line 204 of file thread.hpp.

References threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::get_affinity().

◆ get_id()

auto threadschedule::thread::get_id ( ) const -> std::thread::id
inlinenoexcept

Return std::thread id of the owned thread.

Definition at line 134 of file thread.hpp.

References threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::get_id().

Referenced by threadschedule::advanced::chaos_controller::thread_info().

◆ get_name()

auto threadschedule::thread::get_name ( ) const -> result<std::string>
inline

Query thread name if supported by platform/backend.

Definition at line 190 of file thread.hpp.

References threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::get_name().

Referenced by threadschedule::advanced::chaos_controller::thread_info().

◆ get_nice()

auto threadschedule::thread::get_nice ( ) const -> result<nice_value>
inline

Query current nice value.

Definition at line 176 of file thread.hpp.

References threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::get_nice_value().

◆ get_priority()

auto threadschedule::thread::get_priority ( ) const -> result<priority_level>
inline

Query current portable priority preset.

Definition at line 169 of file thread.hpp.

References threadschedule::detail::basic_thread_backend< ThreadType, OwnershipTag >::get_nice_value().

◆ hardware_concurrency()

static auto threadschedule::thread::hardware_concurrency ( ) -> unsigned
inlinestaticnoexcept

Forward std::thread::hardware_concurrency().

Definition at line 141 of file thread.hpp.

◆ join()

auto threadschedule::thread::join ( ) -> result<void>
inline

Join the thread.

Definition at line 99 of file thread.hpp.

Referenced by threadschedule::advanced::chaos_controller::~chaos_controller().

◆ join_or_throw()

void threadschedule::thread::join_or_throw ( )
inline

Throwing counterpart to join.

Definition at line 106 of file thread.hpp.

◆ joinable()

auto threadschedule::thread::joinable ( ) const -> bool
inlinenoexcept

◆ operator=() [1/2]

auto threadschedule::thread::operator= ( thread &&  ) -> thread &=default
defaultnoexcept

◆ operator=() [2/2]

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

◆ release()

auto threadschedule::thread::release ( ) -> std::thread
inlinenoexcept

Release ownership and return underlying std::thread.

Definition at line 211 of file thread.hpp.

References threadschedule::detail::thread_backend::release().

◆ set_affinity()

auto threadschedule::thread::set_affinity ( thread_affinity const &  affinity) -> result<void>
inline

Apply CPU affinity set.

Definition at line 197 of file thread.hpp.

Referenced by threadschedule::detail::configure_thread().

◆ set_name()

auto threadschedule::thread::set_name ( std::string const &  name) -> result<void>
inline

◆ set_nice()

auto threadschedule::thread::set_nice ( nice_value  value) -> result<void>
inline

Set explicit nice value.

Definition at line 162 of file thread.hpp.

◆ set_priority()

auto threadschedule::thread::set_priority ( priority_level  level) -> result<void>
inline

Set portable priority preset.

Definition at line 155 of file thread.hpp.

Friends And Related Symbol Documentation

◆ detail::native_thread_access

friend struct detail::native_thread_access
friend

Definition at line 217 of file thread.hpp.

◆ thread_view

friend class thread_view
friend

Definition at line 218 of file thread.hpp.


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