|
DelegateMQ
|
Cross-platform thread for any system supporting C++11 std::thread (e.g. Windows, Linux). More...
#include <Thread.h>
Public Member Functions | |
| Thread (const std::string &threadName) | |
| Constructor. | |
| ~Thread () | |
| Destructor. | |
| bool | CreateThread () |
| TaskHandle_t | GetThreadId () |
| Get the ID of this thread instance. | |
| std::string | GetThreadName () |
| Get thread name. | |
| virtual void | DispatchDelegate (std::shared_ptr< dmq::DelegateMsg > msg) |
| Thread (const std::string &threadName) | |
| Constructor. | |
| ~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) |
Public Member Functions inherited from dmq::IThread | |
| virtual | ~IThread ()=default |
| Destructor. | |
Static Public Member Functions | |
| static TaskHandle_t | GetCurrentThreadId () |
| Get the ID of the currently executing thread. | |
| static std::thread::id | GetCurrentThreadId () |
| Get the ID of the currently executing thread. | |
Cross-platform thread for any system supporting C++11 std::thread (e.g. Windows, Linux).
The Thread class creates a worker thread capable of dispatching and invoking asynchronous delegates.
// Create thread with a watchdog timeout thread->CreateThread(std::chrono::milliseconds(2000));
// Or create without a watchdog thread->CreateThread();
WatchdogCheck() is invoked by a Timer instance. In a real-time operating system (RTOS), Timer::ProcessTimers() is typically called from the highest-priority task in the system. This ensures that any user thread becoming unresponsive can still be detected, since WatchdogCheck() runs at a higher priority. For mission-critical systems, a hardware watchdog should also be used as a fail-safe.
| Thread::Thread | ( | const std::string & | threadName | ) |
Constructor.
| Thread::~Thread | ( | ) |
Destructor.
| Thread::Thread | ( | const std::string & | threadName | ) |
Constructor.
| Thread::~Thread | ( | ) |
Destructor.
| bool Thread::CreateThread | ( | ) |
Called once to create the worker thread
| 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.
| [in] | watchdogTimeout | - optional watchdog timeout. |
|
virtual |
Dispatch a DelegateMsg onto this thread. The implementer is responsible for getting the DelegateMsg into an OS message queue. Once DelegateMsg is on the destination thread of control, the IDelegateInvoker::Invoke() function must be called to execute the target function.
| [in] | msg | A shared pointer to the message. |
IThreadInvoker::Invoke() when DelegateMsg is received. Implements dmq::IThread.
|
virtual |
Dispatch and invoke a delegate target on the destination thread.
| [in] | msg | - Delegate message containing target function arguments. |
Implements dmq::IThread.
| void Thread::ExitThread | ( | ) |
Called once at program exit to shut down the worker thread.
|
static |
Get the ID of the currently executing thread.
|
static |
Get the ID of the currently executing thread.
| size_t Thread::GetQueueSize | ( | ) |
Get size of thread message queue.
| std::thread::id Thread::GetThreadId | ( | ) |
Get the ID of this thread instance.
| std::thread::id Thread::GetThreadId | ( | ) |
Get the ID of this thread instance.
|
inline |
Get thread name.
|
inline |
Get thread name.