threadman 0.1.0
Header-only C++23 managed threads, dynamic pools, futures, and executors
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
threadman::ManagedThread Class Reference

#include <thread.hpp>

Classes

struct  ControlBlock
 Heap-resident publishing block — shared by the thread, the manager's registry (as weak_ptr), and any current() lookup. More...
 
struct  Options
 

Public Member Functions

template<class Fn , class... Args>
requires (std::invocable<Fn, std::stop_token, Args...> || std::invocable<Fn, Args...>)
 ManagedThread (Options opts, Fn &&fn, Args &&... args)
 Construct a managed thread; fn may take an optional leading std::stop_token.
 
 ManagedThread (const ManagedThread &)=delete
 
ManagedThreadoperator= (const ManagedThread &)=delete
 
void unregister_from_manager () noexcept
 
 ManagedThread (ManagedThread &&) noexcept=default
 
ManagedThreadoperator= (ManagedThread &&) noexcept=default
 
 ~ManagedThread ()
 
std::uint64_t id () const noexcept
 
const std::string & name () const noexcept
 
std::uint64_t native_id () const noexcept
 
std::optional< std::uint64_t > pool_id () const noexcept
 
bool is_core () const noexcept
 
ThreadState state () const noexcept
 
bool failed () const noexcept
 
std::chrono::nanoseconds run_duration () const noexcept
 Time elapsed since the worker body entered; once exited, the duration from started_at to ended_at.
 
std::stop_source get_stop_source () noexcept
 
std::stop_token get_stop_token () const noexcept
 
bool request_stop () noexcept
 Request the thread to stop. The body sees tok.stop_requested().
 
bool joinable () const noexcept
 
void join ()
 
void detach ()
 
std::thread::id native_thread_id () const noexcept
 Underlying std::jthread::id().
 
std::shared_ptr< ControlBlockcontrol_block () const noexcept
 
ThreadSnapshot snapshot () const
 

Static Public Member Functions

static ControlBlockcurrent () noexcept
 Returns a pointer to the ControlBlock of the currently-executing ManagedThread, or nullptr when called from a thread that wasn't constructed via this class.
 
static const comms::DisplayInfo & display_info ()
 

Constructor & Destructor Documentation

◆ ManagedThread() [1/3]

template<class Fn , class... Args>
requires (std::invocable<Fn, std::stop_token, Args...> || std::invocable<Fn, Args...>)
threadman::ManagedThread::ManagedThread ( Options  opts,
Fn &&  fn,
Args &&...  args 
)
inlineexplicit

Construct a managed thread; fn may take an optional leading std::stop_token.

Registers with opts.manager (or the singleton).

◆ ManagedThread() [2/3]

threadman::ManagedThread::ManagedThread ( const ManagedThread )
delete

◆ ManagedThread() [3/3]

threadman::ManagedThread::ManagedThread ( ManagedThread &&  )
defaultnoexcept

◆ ~ManagedThread()

threadman::ManagedThread::~ManagedThread ( )
inline

Member Function Documentation

◆ control_block()

std::shared_ptr< ControlBlock > threadman::ManagedThread::control_block ( ) const
inlinenoexcept

◆ current()

static ControlBlock * threadman::ManagedThread::current ( )
inlinestaticnoexcept

Returns a pointer to the ControlBlock of the currently-executing ManagedThread, or nullptr when called from a thread that wasn't constructed via this class.

◆ detach()

void threadman::ManagedThread::detach ( )
inline

◆ display_info()

static const comms::DisplayInfo & threadman::ManagedThread::display_info ( )
inlinestatic

◆ failed()

bool threadman::ManagedThread::failed ( ) const
inlinenoexcept

◆ get_stop_source()

std::stop_source threadman::ManagedThread::get_stop_source ( )
inlinenoexcept

◆ get_stop_token()

std::stop_token threadman::ManagedThread::get_stop_token ( ) const
inlinenoexcept

◆ id()

std::uint64_t threadman::ManagedThread::id ( ) const
inlinenoexcept

◆ is_core()

bool threadman::ManagedThread::is_core ( ) const
inlinenoexcept

◆ join()

void threadman::ManagedThread::join ( )
inline

◆ joinable()

bool threadman::ManagedThread::joinable ( ) const
inlinenoexcept

◆ name()

const std::string & threadman::ManagedThread::name ( ) const
inlinenoexcept

◆ native_id()

std::uint64_t threadman::ManagedThread::native_id ( ) const
inlinenoexcept

◆ native_thread_id()

std::thread::id threadman::ManagedThread::native_thread_id ( ) const
inlinenoexcept

Underlying std::jthread::id().

◆ operator=() [1/2]

ManagedThread & threadman::ManagedThread::operator= ( const ManagedThread )
delete

◆ operator=() [2/2]

ManagedThread & threadman::ManagedThread::operator= ( ManagedThread &&  )
defaultnoexcept

◆ pool_id()

std::optional< std::uint64_t > threadman::ManagedThread::pool_id ( ) const
inlinenoexcept

◆ request_stop()

bool threadman::ManagedThread::request_stop ( )
inlinenoexcept

Request the thread to stop. The body sees tok.stop_requested().

◆ run_duration()

std::chrono::nanoseconds threadman::ManagedThread::run_duration ( ) const
inlinenoexcept

Time elapsed since the worker body entered; once exited, the duration from started_at to ended_at.

Returns 0 if not yet started.

◆ snapshot()

ThreadSnapshot threadman::ManagedThread::snapshot ( ) const
inline

◆ state()

ThreadState threadman::ManagedThread::state ( ) const
inlinenoexcept

◆ unregister_from_manager()

void threadman::ManagedThread::unregister_from_manager ( )
inlinenoexcept

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