ADTF
kernel_thread

Class that manages a kernel thread. More...

Inheritance diagram for kernel_thread:
[legend]

Classes

struct  Impl
 
struct  ImplBase
 

Public Member Functions

 kernel_thread ()
 Default constructor. More...
 
 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. More...
 
void Swap (kernel_thread &oOther)
 Swaps two threads. More...
 
bool Joinable () const
 Whether or not the thread is joinable. More...
 
tResult Join (tTimeStamp nTimeout=-1)
 Join the thread. More...
 
tResult Detach ()
 Detaches from the underlying kernel thread. More...
 
tResult SetScheduling (const adtf::services::IKernel::tSchedulingInfo &sScheduling)
 Changes the scheduling parameters of the thread. More...
 
tResult GetScheduling (adtf::services::IKernel::tSchedulingInfo &sScheduling) const
 Retrieves the scheduling parameters of the thread. More...
 
bool IsCurrentThread () const
 Check if the executing thread is managed by this thread object. More...
 

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.

Constructor & Destructor Documentation

◆ kernel_thread()

Default constructor.

Joinable = false.

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.

◆ operator=()

kernel_thread& operator= ( kernel_thread &&  oOther)

Move assignment operator.

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

◆ 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.