ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
kernel_thread

Class that manages a kernel thread. More...

#include <kernel_thread.h>

Inheritance diagram for kernel_thread:
[legend]

Classes

struct  Impl
 
struct  ImplBase
 

Public Member Functions

 kernel_thread ()
 Default constructor.
 
 kernel_thread (const kernel_thread &)=delete
 
 kernel_thread (kernel_thread &&)
 Move constructor.
 
template<typename Callable, typename ... Args>
 kernel_thread (const adtf::services::IKernel::tSchedulingInfo &sScheduling, const char *strName, Callable &&pFunc, Args &&... args)
 Constructor that allows the definition of scheduling parameters.
 
template<typename Callable, typename ... Args>
 kernel_thread (const char *strName, Callable &&pFunc, Args &&... args)
 Constructor that creates a new thread.
 
 ~kernel_thread ()
 Destructor.
 
kernel_threadoperator= (kernel_thread &&oOther)
 Move assignment operator.
 
void Swap (kernel_thread &oOther)
 Swaps two threads.
 
bool Joinable () const
 Whether or not the thread is joinable.
 
tResult Join (tTimeStamp nTimeout=-1)
 Join the thread.
 
tResult Detach ()
 Detaches from the underlying kernel thread.
 
tResult SetScheduling (const adtf::services::IKernel::tSchedulingInfo &sScheduling)
 Changes the scheduling parameters of the thread.
 
tResult GetScheduling (adtf::services::IKernel::tSchedulingInfo &sScheduling) const
 Retrieves the scheduling parameters of the thread.
 
bool IsCurrentThread () const
 Check if the executing thread is managed by this thread object.
 

Private Types

typedef std::shared_ptr< ImplBaseshared_base_type
 

Private Member Functions

template<typename Callable>
std::shared_ptr< Impl< Callable > > MakeCallable (Callable &&pFunc)
 
tResult Create (const char *strName, const adtf::services::IKernel::tSchedulingInfo &sScheduling)
 

Private Attributes

shared_base_type m_pCallable
 

Detailed Description

Class that manages a kernel thread.

This can be use as a drop-in replacement for std::thread In contrast to std::thread, the destructor will join the thread if neccessary.

Definition at line 20 of file kernel_thread.h.

Member Typedef Documentation

◆ shared_base_type

typedef std::shared_ptr<ImplBase> shared_base_type
private

Definition at line 25 of file kernel_thread.h.

Constructor & Destructor Documentation

◆ kernel_thread() [1/3]

Default constructor.

Joinable = false.

References kernel_thread().

Referenced by kernel_thread(), kernel_thread(), kernel_thread(), kernel_thread(), operator=(), and Swap().

◆ kernel_thread() [2/3]

template<typename Callable, typename ... Args>
kernel_thread ( const adtf::services::IKernel::tSchedulingInfo & sScheduling,
const char * strName,
Callable && pFunc,
Args &&... args )
inline

Constructor that allows the definition of scheduling parameters.

Definition at line 76 of file kernel_thread.h.

References kernel_thread().

◆ kernel_thread() [3/3]

template<typename Callable, typename ... Args>
kernel_thread ( const char * strName,
Callable && pFunc,
Args &&... args )
inline

Constructor that creates a new thread.

Definition at line 88 of file kernel_thread.h.

References kernel_thread().

Member Function Documentation

◆ Detach()

tResult Detach ( )

Detaches from the underlying kernel thread.

All resources will be freed once the thread finishes.

Return values
ERR_INVALID_STATEThread is not joinable.

◆ GetScheduling()

tResult GetScheduling ( adtf::services::IKernel::tSchedulingInfo & sScheduling) const

Retrieves the scheduling parameters of the thread.

Parameters
[in]sSchedulingThe scheduling parameters.
Returns
Standard result.

◆ IsCurrentThread()

bool IsCurrentThread ( ) const

Check if the executing thread is managed by this thread object.

Returns
True if the executing thread is managed by this thread object, false otherwise.

◆ Join()

tResult Join ( tTimeStamp nTimeout = -1)

Join the thread.

Parameters
[in]nTimeoutDefines how long this call will block before returning (microseconds, -1 = infinite)
Return values
ERR_INVALID_STATEThread is not joinable.
ERR_TIMEOUTThe timeout has expired.

◆ Joinable()

bool Joinable ( ) const

Whether or not the thread is joinable.

Returns
whether or not the thread is joinable.

◆ MakeCallable()

template<typename Callable>
std::shared_ptr< Impl< Callable > > MakeCallable ( Callable && pFunc)
inlineprivate

Definition at line 51 of file kernel_thread.h.

◆ operator=()

kernel_thread & operator= ( kernel_thread && oOther)

Move assignment operator.

Parameters
[in,out]oOtherThe object that should be moved.
Returns
A reference to this.

References kernel_thread().

◆ SetScheduling()

tResult SetScheduling ( const adtf::services::IKernel::tSchedulingInfo & sScheduling)

Changes the scheduling parameters of the thread.

Parameters
[in]sSchedulingThe new scheduling parameters.
Returns
Standard result.

◆ Swap()

void Swap ( kernel_thread & oOther)

Swaps two threads.

Parameters
[in,out]oOtherThe second thread.

References kernel_thread().

Member Data Documentation

◆ m_pCallable

shared_base_type m_pCallable
private

Definition at line 56 of file kernel_thread.h.