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

This class is used to implement a class that wraps using a thread, it is an alternative to using a thread pool to manage your threads. More...

#include <thread_wrapper.hpp>

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

Public Types

using base_t = private_::thread_base< API, Mdl >
 
using thread_context_t = TWC
 
using lock_traits = typename base_t::lock_traits
 
using thread_traits = typename base_t::thread_traits
 
using os_traits = typename base_t::os_traits
 
using exception_type = typename os_traits::exception_type
 
- Public Types inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >
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

__stdcall wrapper (const wrapper &) noexcept(true) FORCE_INLINE
 Create the wrapper object. Note that the underlying kernel thread will not have been created. More...
 
__stdcall ~wrapper () noexcept(false) override FORCE_INLINE
 
 wrapper (wrapper &&)=delete
 
void operator= (wrapper const &)=delete
 
void operator= (wrapper &&)=delete
 
- Public Member Functions inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >
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)
 

Static Public Attributes

static constexpr ppd::generic_traits::memory_access_modes memory_access_mode
 
- Static Public Attributes inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >
static constexpr ppd::generic_traits::memory_access_modes memory_access_mode =lock_traits::critical_section_type::memory_access_mode
 

Protected Member Functions

__stdcall wrapper (const typename thread_traits::api_params_type::suspend_period_ms ew_=50) noexcept(false) FORCE_INLINE
 
__stdcall wrapper (thread_context_t &&thread_context, const typename thread_traits::api_params_type::suspend_period_ms ew_=50) noexcept(false) FORCE_INLINE
 
virtual bool __fastcall pre_exit () noexcept(false) FORCE_INLINE
 The method used to determine if there has been a request for the thread to exit, and therefore finish processing work, called before attempting to process() a work item. More...
 
virtual bool __fastcall worker_fn (thread_context_t &context) noexcept(false)=0
 This is the main "work" function. Implement it to do some work in the thread. More...
 
thread_traits::api_params_type::states __fastcall process () noexcept(false) override
 Override this function is you want to do some other work to signal the exit of the thread. More...
 
- Protected Member Functions inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >
__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)
 

Protected Attributes

std::atomic< boolexit_requested
 
- Protected Attributes inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >
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
 

Additional Inherited Members

- Public Attributes inherited from jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::private_::thread_base< API, Mdl >
const thread_traits::api_params_type::suspend_period_ms exit_wait_period
 

Detailed Description

template<generic_traits::api_type API, typename Mdl, typename TWC = null_thread_worker_context>
class jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >

This class is used to implement a class that wraps using a thread, it is an alternative to using a thread pool to manage your threads.

Note that the most derived classes' dtor must call private_::thread_base::wait_thread_exit() in it's dtor to ensure that the thread goes out of scope before the object upon which it relies.

Definition at line 53 of file thread_wrapper.hpp.

Member Typedef Documentation

◆ base_t

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
using jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::base_t = private_::thread_base<API, Mdl>

Definition at line 55 of file thread_wrapper.hpp.

◆ exception_type

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
using jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::exception_type = typename os_traits::exception_type

Definition at line 60 of file thread_wrapper.hpp.

◆ lock_traits

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
using jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::lock_traits = typename base_t::lock_traits

Definition at line 57 of file thread_wrapper.hpp.

◆ os_traits

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
using jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::os_traits = typename base_t::os_traits

Definition at line 59 of file thread_wrapper.hpp.

◆ thread_context_t

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
using jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::thread_context_t = TWC

Definition at line 56 of file thread_wrapper.hpp.

◆ thread_traits

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
using jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::thread_traits = typename base_t::thread_traits

Definition at line 58 of file thread_wrapper.hpp.

Constructor & Destructor Documentation

◆ wrapper() [1/4]

template<generic_traits::api_type API, class Mdl , class TWC >
wrapper::wrapper ( const wrapper< API, Mdl, TWC > &  tb)
inlinenoexcept

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

See also
base_t::create_running()

Definition at line 40 of file thread_wrapper_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::wrapper().

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::wrapper().

◆ ~wrapper()

template<generic_traits::api_type API, class Mdl , class TWC >
wrapper::~wrapper
inlineoverridenoexcept

Definition at line 57 of file thread_wrapper_impl.hpp.

◆ wrapper() [2/4]

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::wrapper ( wrapper< API, Mdl, TWC > &&  )
delete

◆ wrapper() [3/4]

template<generic_traits::api_type API, class Mdl , class TWC >
wrapper::wrapper ( const typename thread_traits::api_params_type::suspend_period_ms  ew_ = 50)
inlineexplicitprotectednoexcept

◆ wrapper() [4/4]

template<generic_traits::api_type API, class Mdl , class TWC >
wrapper::wrapper ( thread_context_t &&  thread_context,
const typename thread_traits::api_params_type::suspend_period_ms  ew_ = 50 
)
inlineexplicitprotectednoexcept

Member Function Documentation

◆ operator=() [1/2]

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
void jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::operator= ( wrapper< API, Mdl, TWC > &&  )
delete

◆ operator=() [2/2]

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
void jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::operator= ( wrapper< API, Mdl, TWC > const &  )
delete

◆ pre_exit()

template<generic_traits::api_type API, class Mdl , class TWC >
bool wrapper::pre_exit
inlineprotectedvirtualnoexcept

The method used to determine if there has been a request for the thread to exit, and therefore finish processing work, called before attempting to process() a work item.

Returns
true if an exit from the thread has been requested, otherwise false to continue processing.

Definition at line 45 of file thread_wrapper_impl.hpp.

◆ process()

template<generic_traits::api_type API, class Mdl , class TWC >
wrapper< API, Mdl, TWC >::thread_traits::api_params_type::states wrapper::process
inlineoverrideprotectedvirtualnoexcept

Override this function is you want to do some other work to signal the exit of the thread.

This is primarily used by the destructor to politely tell the thread function to quit. Note that if you override this function you must still implement the exit functionality, otherwise the destructor will time-out and terminate the worker thread.

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

Definition at line 50 of file thread_wrapper_impl.hpp.

◆ worker_fn()

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
virtual bool __fastcall jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::worker_fn ( thread_context_t context)
protectedpure virtualnoexcept

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

Parameters
contextThe context is non-const, to allow the client to modify the state of the context, if they need to. (Although this generalisation may be really required....)
Returns
"false" to continue working. Otherwise return "true" to exit. (Or throw an exception - but that's a messy way to exit...)

Member Data Documentation

◆ exit_requested

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
std::atomic<bool> jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::exit_requested
mutableprotected
Todo:
Consider moving this event into the stack of process() as an automatic variable in there. This may be useful in implementing detached threads. Detached threads may be useful in improving performance of horizontal threading, because the work_complete() lock in them won't have to wait for non-dependent work to complete before it returns.

Definition at line 88 of file thread_wrapper.hpp.

◆ memory_access_mode

template<generic_traits::api_type API, typename Mdl , typename TWC = null_thread_worker_context>
constexpr ppd::generic_traits::memory_access_modes jmmcg::LIBJMMCG_VER_NAMESPACE::ppd::wrapper< API, Mdl, TWC >::memory_access_mode
staticconstexpr
Initial value:

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

Definition at line 65 of file thread_wrapper.hpp.


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