libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl > Class Template Referenceabstract

This class is used to implement a raw class that wraps using a raw thread. More...

#include <thread_base.hpp>

Inheritance diagram for jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >:
[legend]
Collaboration diagram for jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >:
[legend]

Public Types

typedef thread_os_traits< API, Mdl > os_traits
 
typedef os_traits::thread_traits thread_traits
 
typedef os_traits::lock_traits lock_traits
 
typedef os_traits::exception_type exception_type
 

Public Member Functions

virtual void __fastcall create_running () noexcept(false)
 Start the underlying kernel thread. More...
 
const thread_traits::api_params_type &__fastcall params () const noexcept(true) FORCE_INLINE
 
const thread_traits::api_params_type::suspend_count __fastcall suspend () noexcept(true)
 
const thread_traits::api_params_type::suspend_count __fastcall resume () noexcept(true)
 
const thread_traits::api_params_type::states __fastcall state () const noexcept(true)
 
bool __fastcall is_running () const noexcept(true)
 
thread_traits::api_params_type::priority_type __fastcall kernel_priority () const noexcept(false)
 
void __fastcall kernel_priority (const typename thread_traits::api_params_type::priority_type priority) noexcept(false)
 
thread_traits::api_params_type::processor_mask_type __fastcall kernel_affinity () const noexcept(false)
 
void __fastcall kernel_affinity (const typename thread_traits::api_params_type::processor_mask_type &mask) noexcept(false)
 
void __fastcall set_name (char const *name) noexcept(false)
 
virtual const tstring __fastcall to_string () const noexcept(false)
 
virtual void __fastcall request_exit () const noexcept(false)
 

Public Attributes

const thread_traits::api_params_type::suspend_period_ms exit_wait_period
 

Static Public Attributes

static constexpr ppd::generic_traits::memory_access_modes memory_access_mode =lock_traits::critical_section_type::memory_access_mode
 

Protected Member Functions

__stdcall thread_base (const typename thread_traits::api_params_type::suspend_period_ms exit_wait_p) noexcept(false)
 Create the wrapper object. Note that the underlying kernel thread will not have been started. More...
 
__stdcall thread_base (const thread_base &tb) noexcept(true)
 
virtual __stdcall ~thread_base () noexcept(false)
 Thread base dtor. More...
 
void __fastcall wait_thread_exit () noexcept(false)
 
virtual thread_traits::api_params_type::states __fastcall process () noexcept(false)=0
 This is the main "work" function. Implement it to do some work in the thread. More...
 

Protected Attributes

os_traits::thread_exception exception_thrown_in_thread
 This is to allow exceptions thrown in the contained thread to be (hopefully) propagated back to another thread on which that exception can be caught & handled. More...
 
lock_traits::critical_section_type thread_params_lock
 
thread_traits::api_params_type thread_params
 

Detailed Description

template<generic_traits::api_type API, typename Mdl>
class jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >

This class is used to implement a raw class that wraps using a raw thread.

This provides the thread-as-an-active-class threading model.

Definition at line 32 of file thread_base.hpp.

Member Typedef Documentation

◆ exception_type

◆ lock_traits

◆ os_traits

Definition at line 34 of file thread_base.hpp.

◆ thread_traits

Constructor & Destructor Documentation

◆ thread_base() [1/2]

template<generic_traits::api_type API, typename Mdl >
jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::thread_base ( const typename thread_traits::api_params_type::suspend_period_ms  exit_wait_p)
inlineexplicitprotectednoexcept

Create the wrapper object. Note that the underlying kernel thread will not have been started.

Parameters
exit_wait_pThe length of time, in ms, that the dtor will wait for the thread to exit before terminating the thread. Such termination may cause undefined behaviour to result, depending upon the details of how the underlying OS manages thread termination.

Definition at line 153 of file thread_base_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::exit_wait_period, and jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::thread_params.

◆ thread_base() [2/2]

◆ ~thread_base()

template<generic_traits::api_type API, typename Mdl >
jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::~thread_base
inlineprotectedvirtualnoexcept

Thread base dtor.

Don't throw any registered "exception_thrown_in_thread" here, because evil leaks will happen in the thread pool. YUCK. Ignore any bad exit states from the thread too. Tough. Ensure that wait_thread_exit() is called from the most-derived dtor, otherwise UB will happen.

See also
wait_thread_exit()

Definition at line 167 of file thread_base_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::thread_params.

Member Function Documentation

◆ create_running()

◆ is_running()

◆ kernel_affinity() [1/2]

◆ kernel_affinity() [2/2]

◆ kernel_priority() [1/2]

◆ kernel_priority() [2/2]

◆ params()

◆ process()

template<generic_traits::api_type API, typename Mdl >
virtual thread_traits::api_params_type::states __fastcall jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::process ( )
protectedpure virtualnoexcept

This is the main "work" function. Implement it to do some work in the thread.

Any exceptions thrown will be caught in the core_work_fn() and reported to the user (or calling thread) by re-throwing, at the latest, in the destructor.

Implemented in jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >, jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< os_traits::thread_traits::api_params_type::api_type, os_traits::thread_traits::model_type >, and jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, std::function< void()> >.

◆ request_exit()

template<generic_traits::api_type API, typename Mdl >
void jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::request_exit
inlinevirtualnoexcept

We don't gobble exceptions, because thread_pools might want to know if a member fails... TODO Is this true?: Note that if this method throws an exception, wait_thread_exit() may lock up unless the situation is managed further.

Definition at line 198 of file thread_base_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::thread_params.

◆ resume()

Definition at line 67 of file thread_base_impl.hpp.

◆ set_name()

template<generic_traits::api_type API, typename Mdl >
void jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::set_name ( char const *  name)
inlinenoexcept

◆ state()

◆ suspend()

◆ to_string()

template<generic_traits::api_type API, typename Mdl >
const tstring jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::to_string
inlinevirtualnoexcept

Reimplemented in jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::pool::private_::pool_thread< OST, ExitReq >, jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::pool::private_::pool_thread< thread_os_traits< generic_traits::api_type::posix_pthreads, heavyweight_threading >, PTT::template pool_thread_queue_details< pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue >::exit_requested_type >, jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::pool::private_::pool_thread< thread_os_traits< generic_traits::api_type::posix_pthreads, sequential_mode >, PTT::template pool_thread_queue_details< pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue >::exit_requested_type >, jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::pool::private_::pool_thread< thread_os_traits< generic_traits::api_type::posix_pthreads, heavyweight_threading >, PTT::template pool_thread_queue_details< pool_traits::work_distribution_mode_t::queue_model_t::thread_owns_queue< pool_traits::work_distribution_mode_t::queue_model_t::stealing_mode_t::random > >::exit_requested_type >, and jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::pool::private_::pool_thread< thread_os_traits< generic_traits::api_type::posix_pthreads, sequential_mode >, PTT::template pool_thread_queue_details< QM >::exit_requested_type >.

Definition at line 143 of file thread_base_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::exception_thrown_in_thread, jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::exit_wait_period, and jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::thread_params.

◆ wait_thread_exit()

template<generic_traits::api_type API, typename Mdl >
void jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::wait_thread_exit
inlineprotectednoexcept

This must be called from the most-derived class, otherwise you could get "pure virtual call" errors, because process() could be called, or other dependent class members could be deleted before the thread exists.

Definition at line 175 of file thread_base_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::exit_wait_period, and jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::thread_params.

Member Data Documentation

◆ exception_thrown_in_thread

template<generic_traits::api_type API, typename Mdl >
os_traits::thread_exception jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::exception_thrown_in_thread
protected

This is to allow exceptions thrown in the contained thread to be (hopefully) propagated back to another thread on which that exception can be caught & handled.

Definition at line 73 of file thread_base.hpp.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::thread_base(), and jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::to_string().

◆ exit_wait_period

◆ memory_access_mode

template<generic_traits::api_type API, typename Mdl >
constexpr ppd::generic_traits::memory_access_modes jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >::memory_access_mode =lock_traits::critical_section_type::memory_access_mode
staticconstexpr

To assist in allowing compile-time computation of the algorithmic order of the threading model.

Definition at line 42 of file thread_base.hpp.

◆ thread_params

◆ thread_params_lock


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