libjmmcg  build_2783
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::ppd::thread< API, Mdl > Class Template Referencefinal

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, in a C++ std::thread-style manner. More...

#include <thread_wrapper.hpp>

Inheritance diagram for jmmcg::ppd::thread< API, Mdl >:
[legend]
Collaboration diagram for jmmcg::ppd::thread< API, Mdl >:
[legend]

Public Types

using base_t = wrapper< API, Mdl, std::function< void()> >
 
using thread_context_t = typename base_t::thread_context_t
 
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 base_t::exception_type
 
- Public Types inherited from jmmcg::ppd::wrapper< API, Mdl, std::function< void()> >
using base_t = private_::thread_base< API, Mdl >
 
using thread_context_t = std::function< void()>
 
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::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 thread (const typename thread_traits::api_params_type::suspend_period_ms ew_=50) noexcept(false) FORCE_INLINE
 
template<class ProcFn >
__stdcall thread (ProcFn &&proc_fn, const typename thread_traits::api_params_type::suspend_period_ms ew_=50) noexcept(false) FORCE_INLINE
 Create the wrapper object. Note that the underlying kernel thread will have been created, so the proc_fn will execute in the underlying thread (if any). More...
 
template<class ProcFn >
 thread (ProcFn &&proc_fn, const typename thread_traits::api_params_type::suspend_period_ms ew) noexcept(false)
 
- Public Member Functions inherited from jmmcg::ppd::wrapper< API, Mdl, std::function< void()> >
__stdcall wrapper (const wrapper &) noexcept(true) FORCE_INLINE
 Create the wrapper object. Note that the underlying kernel thread will not have been created. More...
 
 wrapper (wrapper &&)=delete
 
__stdcall ~wrapper () noexcept(false) override FORCE_INLINE
 
void operator= (wrapper const &)=delete
 
void operator= (wrapper &&)=delete
 
- Public Member Functions inherited from jmmcg::ppd::private_::thread_base< API, Mdl >
virtual void __fastcall create_running () noexcept(false) FORCE_INLINE
 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) FORCE_INLINE
 
const thread_traits::api_params_type::suspend_count __fastcall resume () noexcept(true) FORCE_INLINE
 
const thread_traits::api_params_type::states __fastcall state () const noexcept(true) FORCE_INLINE
 
bool __fastcall is_running () const noexcept(true) FORCE_INLINE
 
thread_traits::api_params_type::priority_type __fastcall kernel_priority () const noexcept(false) FORCE_INLINE
 
void __fastcall kernel_priority (const typename thread_traits::api_params_type::priority_type priority) noexcept(false) FORCE_INLINE
 
thread_traits::api_params_type::processor_mask_type __fastcall kernel_affinity () const noexcept(false) FORCE_INLINE
 
void __fastcall kernel_affinity (const typename thread_traits::api_params_type::processor_mask_type &mask) noexcept(false) FORCE_INLINE
 
virtual const tstring __fastcall to_string () const noexcept(false)
 
virtual void __fastcall request_exit () const noexcept(false) FORCE_INLINE
 
template<>
const thread_base< generic_traits::MS_Win32, heavyweight_threading >::thread_traits::api_params_type::suspend_count __fastcall suspend () noexcept(true)
 

Static Public Attributes

static constexpr ppd::generic_traits::memory_access_modes memory_access_mode
 
- Static Public Attributes inherited from jmmcg::ppd::wrapper< API, Mdl, std::function< void()> >
static constexpr ppd::generic_traits::memory_access_modes memory_access_mode
 
- Static Public Attributes inherited from jmmcg::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
 

Additional Inherited Members

- Public Attributes inherited from jmmcg::ppd::private_::thread_base< API, Mdl >
const thread_traits::api_params_type::suspend_period_ms exit_wait_period
 
- Protected Member Functions inherited from jmmcg::ppd::wrapper< API, Mdl, std::function< void()> >
__stdcall wrapper (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::ppd::private_::thread_base< API, Mdl >
__stdcall thread_base (const typename thread_traits::api_params_type::suspend_period_ms exit_wait_p) noexcept(false) FORCE_INLINE
 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) FORCE_INLINE
 
virtual __stdcall ~thread_base () noexcept(false) FORCE_INLINE
 Thread base dtor. More...
 
void __fastcall wait_thread_exit () noexcept(false) FORCE_INLINE
 
- Protected Attributes inherited from jmmcg::ppd::wrapper< API, Mdl, std::function< void()> >
std::atomic< boolexit_requested
 
- Protected Attributes inherited from jmmcg::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
 

Detailed Description

template<generic_traits::api_type API, typename Mdl>
class jmmcg::ppd::thread< API, Mdl >

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, in a C++ std::thread-style manner.

See also
wrapper, std::thread

Definition at line 118 of file thread_wrapper.hpp.

Member Typedef Documentation

◆ base_t

template<generic_traits::api_type API, typename Mdl>
using jmmcg::ppd::thread< API, Mdl >::base_t = wrapper<API, Mdl, std::function<void()> >

Definition at line 120 of file thread_wrapper.hpp.

◆ exception_type

template<generic_traits::api_type API, typename Mdl>
using jmmcg::ppd::thread< API, Mdl >::exception_type = typename base_t::exception_type

Definition at line 125 of file thread_wrapper.hpp.

◆ lock_traits

template<generic_traits::api_type API, typename Mdl>
using jmmcg::ppd::thread< API, Mdl >::lock_traits = typename base_t::lock_traits

Definition at line 122 of file thread_wrapper.hpp.

◆ os_traits

template<generic_traits::api_type API, typename Mdl>
using jmmcg::ppd::thread< API, Mdl >::os_traits = typename base_t::os_traits

Definition at line 124 of file thread_wrapper.hpp.

◆ thread_context_t

template<generic_traits::api_type API, typename Mdl>
using jmmcg::ppd::thread< API, Mdl >::thread_context_t = typename base_t::thread_context_t

Definition at line 121 of file thread_wrapper.hpp.

◆ thread_traits

template<generic_traits::api_type API, typename Mdl>
using jmmcg::ppd::thread< API, Mdl >::thread_traits = typename base_t::thread_traits

Definition at line 123 of file thread_wrapper.hpp.

Constructor & Destructor Documentation

◆ thread() [1/3]

template<generic_traits::api_type API, class Mdl >
jmmcg::ppd::thread< API, Mdl >::thread ( const typename thread_traits::api_params_type::suspend_period_ms  ew_ = 50)
inlineexplicitnoexcept

Definition at line 96 of file thread_wrapper_impl.hpp.

◆ thread() [2/3]

template<generic_traits::api_type API, typename Mdl>
template<class ProcFn >
__stdcall jmmcg::ppd::thread< API, Mdl >::thread ( ProcFn &&  proc_fn,
const typename thread_traits::api_params_type::suspend_period_ms  ew_ = 50 
)
explicitnoexcept

Create the wrapper object. Note that the underlying kernel thread will have been created, so the proc_fn will execute in the underlying thread (if any).

This ctor requires a memory allocation for the functor.

Parameters
proc_fnThe functor that will executed by the underlying kernel thread (if any).
See also
create_running()

◆ thread() [3/3]

template<generic_traits::api_type API, typename Mdl>
template<class ProcFn >
jmmcg::ppd::thread< API, Mdl >::thread ( ProcFn &&  proc_fn,
const typename thread_traits::api_params_type::suspend_period_ms  ew 
)
inlinenoexcept

Definition at line 102 of file thread_wrapper_impl.hpp.

Member Data Documentation

◆ memory_access_mode

template<generic_traits::api_type API, typename Mdl>
constexpr ppd::generic_traits::memory_access_modes jmmcg::ppd::thread< API, Mdl >::memory_access_mode
staticconstexpr
Initial value:

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

Definition at line 130 of file thread_wrapper.hpp.


The documentation for this class was generated from the following files:
jmmcg::ppd::generic_traits::memory_access_modes::erew_memory_access
Exclusive-Read, Exclusive-Write memory access.
jmmcg::ppd::generic_traits::memory_access_modes::crew_memory_access
Concurrent-Read, Exclusive-Write memory access.
jmmcg::ppd::wrapper< API, Mdl, std::function< void()> >::memory_access_mode
static constexpr ppd::generic_traits::memory_access_modes memory_access_mode
Definition: thread_wrapper.hpp:63