commonlib
FunctionThread Class Reference

Provides a mechanism for executing a method in a thread. More...

#include <functionthread.h>

Inheritance diagram for FunctionThread:
ThreadEx

Public Types

using CallbackFunction = std::function< void(void)>
 

Public Member Functions

 FunctionThread (CallbackFunction callback=nullptr)
 Initializes a new instance of the FunctionThread class. More...
 
const CallbackFunction & getCallback () const
 Get callback function. More...
 
void setCallback (const CallbackFunction &value)
 Set callback function. More...
 
- Public Member Functions inherited from ThreadEx
virtual void start ()
 Starts the execution of a thread.
 
virtual void stop ()
 Terminate and wait for the thread to terminate.
 
void terminate ()
 Terminate sets the thread's Terminated property to true, signaling that the thread should be terminated as soon as possible.
 
void waitFor ()
 Waits for the thread to terminate.
 
const ThreadExPriority & getPriority () const
 Get thread's scheduling priority relative to other threads in the process. More...
 
void setPriority (ThreadExPriority priority)
 Set thread's scheduling priority relative to other threads in the process. More...
 
std::recursive_mutex & getLock ()
 Get thread's locking object. More...
 
const std::atomic< bool > & getTerminated () const
 Returns thread's terminated signal. More...
 
const std::atomic< bool > & getFinished () const
 Returns true if thread has already been finished. More...
 
bool getStarted () const
 Returns true if thread is started. More...
 
ThreadExceptionAdapter * getExceptionAdapter ()
 Returns exception information holder. More...
 
void setExceptionAdapter (ThreadExceptionAdapter *exceptionAdapter)
 Sets exception information holder. More...
 
const std::thread::id getThreadId () const
 Returns thread id.
 

Protected Member Functions

void execute () override
 Provides an abstract or pure virtual method to contain the code which executes when the thread is run.
 
- Protected Member Functions inherited from ThreadEx
void setThreadName (const char *name)
 Set current thread name (you must call it from the thread)
 

Additional Inherited Members

- Protected Attributes inherited from ThreadEx
std::recursive_mutex lock
 
std::atomic< bool > terminated
 
std::atomic< bool > finished
 
ThreadExceptionAdapter * exceptionAdapter {}
 

Detailed Description

Provides a mechanism for executing a method in a thread.

Constructor & Destructor Documentation

◆ FunctionThread()

FunctionThread::FunctionThread ( CallbackFunction  callback = nullptr)

Initializes a new instance of the FunctionThread class.

Parameters
callbacka callback function you want the FunctionThread to execute.

Member Function Documentation

◆ getCallback()

const CallbackFunction& FunctionThread::getCallback ( ) const

Get callback function.

Returns
Callback function.

◆ setCallback()

void FunctionThread::setCallback ( const CallbackFunction &  value)

Set callback function.

Parameters
valueA function that will be called.

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