DelegateMQ
Loading...
Searching...
No Matches
Thread Class Reference

Cross-platform thread for any system supporting C++11 std::thread (e.g. Windows, Linux). More...

#include <Thread.h>

Inheritance diagram for Thread:
dmq::IThread dmq::IThread dmq::IThread dmq::IThread dmq::IThread dmq::IThread dmq::IThread

Signals

void SignalDispatch (std::shared_ptr< dmq::DelegateMsg > msg)
 

Public Member Functions

 Thread (const std::string &threadName, size_t maxQueueSize=0)
 
 ~Thread ()
 
bool CreateThread ()
 
void ExitThread ()
 
osThreadId_t GetThreadId ()
 
void SetThreadPriority (osPriority_t priority)
 
osPriority_t GetThreadPriority ()
 Get current priority.
 
std::string GetThreadName ()
 
virtual void DispatchDelegate (std::shared_ptr< dmq::DelegateMsg > msg) override
 Enqueues a delegate message for execution on this thread.
 
 Thread (const std::string &threadName, size_t maxQueueSize=0)
 
 ~Thread ()
 Destructor.
 
bool CreateThread ()
 
void ExitThread ()
 Terminate the thread gracefully.
 
TaskHandle_t GetThreadId ()
 Get the ID of this thread instance.
 
std::string GetThreadName ()
 Get thread name.
 
void SetThreadPriority (int priority)
 
void SetStackMem (StackType_t *stackBuffer, uint32_t stackSizeInWords)
 
virtual void DispatchDelegate (std::shared_ptr< dmq::DelegateMsg > msg) override
 Enqueues a delegate message for execution on this thread.
 
 Thread (const std::string &threadName)
 
 ~Thread ()
 Destructor.
 
bool CreateThread ()
 Create and start the internal QThread.
 
void ExitThread ()
 Stop the QThread.
 
QThread * GetThreadId ()
 Get the QThread pointer (used as the ID)
 
std::string GetThreadName () const
 
virtual void DispatchDelegate (std::shared_ptr< dmq::DelegateMsg > msg) override
 Enqueues a delegate message for execution on this thread.
 
 Thread (const std::string &threadName, size_t maxQueueSize=0)
 
 ~Thread ()
 Destructor.
 
bool CreateThread (std::optional< dmq::Duration > watchdogTimeout=std::nullopt)
 
void ExitThread ()
 Called once at program exit to shut down the worker thread.
 
std::thread::id GetThreadId ()
 Get the ID of this thread instance.
 
std::string GetThreadName ()
 Get thread name.
 
size_t GetQueueSize ()
 Get size of thread message queue.
 
virtual void DispatchDelegate (std::shared_ptr< dmq::DelegateMsg > msg)
 
 Thread (const std::string &threadName, size_t maxQueueSize=0)
 
 ~Thread ()
 Destructor.
 
bool CreateThread ()
 
void ExitThread ()
 Terminate the thread gracefully.
 
TX_THREAD * GetThreadId ()
 Get the ID of this thread instance.
 
void SetThreadPriority (UINT priority)
 
UINT GetThreadPriority ()
 Get current priority.
 
std::string GetThreadName ()
 Get thread name.
 
virtual void DispatchDelegate (std::shared_ptr< dmq::DelegateMsg > msg) override
 Enqueues a delegate message for execution on this thread.
 
 Thread (const std::string &threadName, size_t maxQueueSize=0)
 
virtual ~Thread ()
 Destructor.
 
bool CreateThread (std::optional< dmq::Duration > watchdogTimeout=std::nullopt)
 
void ExitThread ()
 Called once at program exit to shut down the worker thread.
 
DWORD GetThreadId ()
 Get the ID of this thread instance.
 
std::string GetThreadName ()
 Get thread name.
 
size_t GetQueueSize ()
 Get size of thread message queue.
 
virtual void DispatchDelegate (std::shared_ptr< dmq::DelegateMsg > msg) override
 
 Thread (const std::string &threadName)
 
 ~Thread ()
 
bool CreateThread ()
 
void ExitThread ()
 
k_tid_t GetThreadId ()
 
std::string GetThreadName ()
 
virtual void DispatchDelegate (std::shared_ptr< dmq::DelegateMsg > msg) override
 Enqueues a delegate message for execution on this thread.
 
- Public Member Functions inherited from dmq::IThread
virtual ~IThread ()=default
 Destructor.
 

Static Public Member Functions

static osThreadId_t GetCurrentThreadId ()
 
static TaskHandle_t GetCurrentThreadId ()
 Get the ID of the currently executing thread.
 
static QThread * GetCurrentThreadId ()
 Get the current executing QThread pointer.
 
static std::thread::id GetCurrentThreadId ()
 Get the ID of the currently executing thread.
 
static TX_THREAD * GetCurrentThreadId ()
 Get the ID of the currently executing thread.
 
static DWORD GetCurrentThreadId ()
 Get the ID of the currently executing thread.
 
static k_tid_t GetCurrentThreadId ()
 

Static Public Attributes

static const uint32_t DEFAULT_QUEUE_SIZE = 20
 Default queue size if 0 is passed.
 
static const size_t DEFAULT_QUEUE_SIZE = 20
 Default queue size if 0 is passed.
 
static const ULONG DEFAULT_QUEUE_SIZE = 20
 Default queue size if 0 is passed.
 

Detailed Description

Cross-platform thread for any system supporting C++11 std::thread (e.g. Windows, Linux).

Windows-native thread for systems using the Win32 API.

The Thread class creates a worker thread capable of dispatching and invoking asynchronous delegates.

Constructor & Destructor Documentation

◆ Thread() [1/7]

Thread::Thread ( const std::string & threadName,
size_t maxQueueSize = 0 )

Constructor

Parameters
threadNameName for the thread
maxQueueSizeMax number of messages in queue (0 = Default 20)

◆ ~Thread() [1/7]

Thread::~Thread ( )

◆ Thread() [2/7]

Thread::Thread ( const std::string & threadName,
size_t maxQueueSize = 0 )

Constructor

Parameters
threadNameName for the FreeRTOS task
maxQueueSizeMax number of messages in queue (0 = Default 20)

◆ ~Thread() [2/7]

Thread::~Thread ( )

Destructor.

◆ Thread() [3/7]

Thread::Thread ( const std::string & threadName)

Constructor

Parameters
threadNameName for debugging (QObject::objectName)

◆ ~Thread() [3/7]

Thread::~Thread ( )

Destructor.

◆ Thread() [4/7]

Thread::Thread ( const std::string & threadName,
size_t maxQueueSize = 0 )

Constructor

Parameters
threadNameThe name of the thread for debugging.
maxQueueSizeThe maximum number of messages allowed in the queue. 0 means unlimited (no back pressure).

◆ ~Thread() [4/7]

Thread::~Thread ( )

Destructor.

◆ Thread() [5/7]

Thread::Thread ( const std::string & threadName,
size_t maxQueueSize = 0 )

Constructor

Parameters
threadNameName for the ThreadX thread
maxQueueSizeMax number of messages in queue (0 = Default 20)

◆ ~Thread() [5/7]

Thread::~Thread ( )

Destructor.

◆ Thread() [6/7]

Thread::Thread ( const std::string & threadName,
size_t maxQueueSize = 0 )

Constructor

Parameters
threadNameThe name of the thread for debugging.
maxQueueSizeThe maximum number of messages allowed in the queue. 0 means unlimited (no back pressure).

◆ ~Thread() [6/7]

virtual Thread::~Thread ( )
virtual

Destructor.

◆ Thread() [7/7]

Thread::Thread ( const std::string & threadName)

◆ ~Thread() [7/7]

Thread::~Thread ( )

Member Function Documentation

◆ CreateThread() [1/7]

bool Thread::CreateThread ( )

◆ CreateThread() [2/7]

bool Thread::CreateThread ( )

Called once to create the worker thread

Returns
TRUE if thread is created. FALSE otherwise.

◆ CreateThread() [3/7]

bool Thread::CreateThread ( )

Create and start the internal QThread.

◆ CreateThread() [4/7]

bool Thread::CreateThread ( )

Called once to create the worker thread

Returns
TRUE if thread is created. FALSE otherwise.

◆ CreateThread() [5/7]

bool Thread::CreateThread ( )

◆ CreateThread() [6/7]

bool Thread::CreateThread ( std::optional< dmq::Duration > watchdogTimeout = std::nullopt)

Called once to create the worker thread. If watchdogTimeout value provided, the maximum watchdog interval is used. Otherwise no watchdog.

Parameters
[in]watchdogTimeout- optional watchdog timeout.
Returns
TRUE if thread is created. FALSE otherwise.

◆ CreateThread() [7/7]

bool Thread::CreateThread ( std::optional< dmq::Duration > watchdogTimeout = std::nullopt)

Called once to create the worker thread. If watchdogTimeout value provided, the maximum watchdog interval is used. Otherwise no watchdog.

Parameters
[in]watchdogTimeout- optional watchdog timeout.
Returns
TRUE if thread is created. FALSE otherwise.

◆ DispatchDelegate() [1/7]

virtual void Thread::DispatchDelegate ( std::shared_ptr< dmq::DelegateMsg > msg)
virtual

Dispatch and invoke a delegate target on the destination thread.

Parameters
[in]msg- Delegate message containing target function arguments.

Implements dmq::IThread.

◆ DispatchDelegate() [2/7]

void Thread::DispatchDelegate ( std::shared_ptr< dmq::DelegateMsg > msg)
overridevirtual

Enqueues a delegate message for execution on this thread.

This function is called by the source thread (the caller). The implementation must thread-safely transfer ownership of the msg into the target thread's processing queue.

Once the message is received by the target thread's main loop, that loop is responsible for calling IInvoker::Invoke(msg) to actually execute the function.

Parameters
[in]msgA shared pointer to the delegate message. This pointer must remain valid until the target thread finishes execution.

Implements dmq::IThread.

◆ DispatchDelegate() [3/7]

virtual void Thread::DispatchDelegate ( std::shared_ptr< dmq::DelegateMsg > msg)
overridevirtual

Enqueues a delegate message for execution on this thread.

This function is called by the source thread (the caller). The implementation must thread-safely transfer ownership of the msg into the target thread's processing queue.

Once the message is received by the target thread's main loop, that loop is responsible for calling IInvoker::Invoke(msg) to actually execute the function.

Parameters
[in]msgA shared pointer to the delegate message. This pointer must remain valid until the target thread finishes execution.

Implements dmq::IThread.

◆ DispatchDelegate() [4/7]

virtual void Thread::DispatchDelegate ( std::shared_ptr< dmq::DelegateMsg > msg)
overridevirtual

Enqueues a delegate message for execution on this thread.

This function is called by the source thread (the caller). The implementation must thread-safely transfer ownership of the msg into the target thread's processing queue.

Once the message is received by the target thread's main loop, that loop is responsible for calling IInvoker::Invoke(msg) to actually execute the function.

Parameters
[in]msgA shared pointer to the delegate message. This pointer must remain valid until the target thread finishes execution.

Implements dmq::IThread.

◆ DispatchDelegate() [5/7]

virtual void Thread::DispatchDelegate ( std::shared_ptr< dmq::DelegateMsg > msg)
overridevirtual

Enqueues a delegate message for execution on this thread.

This function is called by the source thread (the caller). The implementation must thread-safely transfer ownership of the msg into the target thread's processing queue.

Once the message is received by the target thread's main loop, that loop is responsible for calling IInvoker::Invoke(msg) to actually execute the function.

Parameters
[in]msgA shared pointer to the delegate message. This pointer must remain valid until the target thread finishes execution.

Implements dmq::IThread.

◆ DispatchDelegate() [6/7]

virtual void Thread::DispatchDelegate ( std::shared_ptr< dmq::DelegateMsg > msg)
overridevirtual

Dispatch and invoke a delegate target on the destination thread.

Parameters
[in]msg- Delegate message containing target function arguments.

Implements dmq::IThread.

◆ DispatchDelegate() [7/7]

void Thread::DispatchDelegate ( std::shared_ptr< dmq::DelegateMsg > msg)
overridevirtual

Enqueues a delegate message for execution on this thread.

This function is called by the source thread (the caller). The implementation must thread-safely transfer ownership of the msg into the target thread's processing queue.

Once the message is received by the target thread's main loop, that loop is responsible for calling IInvoker::Invoke(msg) to actually execute the function.

Parameters
[in]msgA shared pointer to the delegate message. This pointer must remain valid until the target thread finishes execution.

Implements dmq::IThread.

◆ ExitThread() [1/7]

void Thread::ExitThread ( )

◆ ExitThread() [2/7]

void Thread::ExitThread ( )

Terminate the thread gracefully.

◆ ExitThread() [3/7]

void Thread::ExitThread ( )

Stop the QThread.

◆ ExitThread() [4/7]

void Thread::ExitThread ( )

Called once at program exit to shut down the worker thread.

◆ ExitThread() [5/7]

void Thread::ExitThread ( )

Terminate the thread gracefully.

◆ ExitThread() [6/7]

void Thread::ExitThread ( )

Called once at program exit to shut down the worker thread.

◆ ExitThread() [7/7]

void Thread::ExitThread ( )

◆ GetCurrentThreadId() [1/7]

k_tid_t Thread::GetCurrentThreadId ( )
static

◆ GetCurrentThreadId() [2/7]

static TaskHandle_t Thread::GetCurrentThreadId ( )
static

Get the ID of the currently executing thread.

◆ GetCurrentThreadId() [3/7]

static QThread * Thread::GetCurrentThreadId ( )
static

Get the current executing QThread pointer.

◆ GetCurrentThreadId() [4/7]

static std::thread::id Thread::GetCurrentThreadId ( )
static

Get the ID of the currently executing thread.

◆ GetCurrentThreadId() [5/7]

static TX_THREAD * Thread::GetCurrentThreadId ( )
static

Get the ID of the currently executing thread.

◆ GetCurrentThreadId() [6/7]

static DWORD Thread::GetCurrentThreadId ( )
static

Get the ID of the currently executing thread.

◆ GetCurrentThreadId() [7/7]

static k_tid_t Thread::GetCurrentThreadId ( )
static

◆ GetQueueSize() [1/2]

size_t Thread::GetQueueSize ( )

Get size of thread message queue.

◆ GetQueueSize() [2/2]

size_t Thread::GetQueueSize ( )

Get size of thread message queue.

◆ GetThreadId() [1/7]

k_tid_t Thread::GetThreadId ( )

◆ GetThreadId() [2/7]

TaskHandle_t Thread::GetThreadId ( )

Get the ID of this thread instance.

◆ GetThreadId() [3/7]

QThread * Thread::GetThreadId ( )

Get the QThread pointer (used as the ID)

◆ GetThreadId() [4/7]

std::thread::id Thread::GetThreadId ( )

Get the ID of this thread instance.

◆ GetThreadId() [5/7]

TX_THREAD * Thread::GetThreadId ( )

Get the ID of this thread instance.

◆ GetThreadId() [6/7]

DWORD Thread::GetThreadId ( )

Get the ID of this thread instance.

◆ GetThreadId() [7/7]

k_tid_t Thread::GetThreadId ( )

◆ GetThreadName() [1/7]

std::string Thread::GetThreadName ( )
inline

◆ GetThreadName() [2/7]

std::string Thread::GetThreadName ( )
inline

Get thread name.

◆ GetThreadName() [3/7]

std::string Thread::GetThreadName ( )
inline

Get thread name.

◆ GetThreadName() [4/7]

std::string Thread::GetThreadName ( )
inline

Get thread name.

◆ GetThreadName() [5/7]

std::string Thread::GetThreadName ( )
inline

Get thread name.

◆ GetThreadName() [6/7]

std::string Thread::GetThreadName ( )
inline

◆ GetThreadName() [7/7]

std::string Thread::GetThreadName ( ) const
inline

◆ GetThreadPriority() [1/2]

UINT Thread::GetThreadPriority ( )

Get current priority.

◆ GetThreadPriority() [2/2]

UINT Thread::GetThreadPriority ( )

Get current priority.

◆ SetStackMem()

void Thread::SetStackMem ( StackType_t * stackBuffer,
uint32_t stackSizeInWords )

Optional: Provide a static buffer for the task stack to avoid Heap usage.

Parameters
stackBufferPointer to a buffer of type StackType_t.
stackSizeInWordsSize of the buffer in WORDS (not bytes).

◆ SetThreadPriority() [1/3]

void Thread::SetThreadPriority ( int priority)

Set the FreeRTOS Task Priority. Can be called before or after CreateThread().

Parameters
priorityFreeRTOS priority level (0 to configMAX_PRIORITIES-1)

◆ SetThreadPriority() [2/3]

void Thread::SetThreadPriority ( osPriority_t priority)

Set the thread priority. Can be called before or after CreateThread().

◆ SetThreadPriority() [3/3]

void Thread::SetThreadPriority ( UINT priority)

Set the ThreadX Priority (0 = Highest). Can be called before or after CreateThread().

◆ SignalDispatch

void Thread::SignalDispatch ( std::shared_ptr< dmq::DelegateMsg > msg)
signal

Member Data Documentation

◆ DEFAULT_QUEUE_SIZE [1/3]

const uint32_t Thread::DEFAULT_QUEUE_SIZE = 20
static

Default queue size if 0 is passed.

◆ DEFAULT_QUEUE_SIZE [2/3]

const size_t Thread::DEFAULT_QUEUE_SIZE = 20
static

Default queue size if 0 is passed.

◆ DEFAULT_QUEUE_SIZE [3/3]

const ULONG Thread::DEFAULT_QUEUE_SIZE = 20
static

Default queue size if 0 is passed.


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