Cross-platform thread for any system supporting C++11 std::thread (e.g. Windows, Linux).
More...
#include <Thread.h>
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.
◆ Thread() [1/2]
| Thread::Thread |
( |
const std::string & | threadName | ) |
|
◆ ~Thread() [1/2]
◆ Thread() [2/2]
| Thread::Thread |
( |
const std::string & | threadName, |
|
|
size_t | maxQueueSize = 0 ) |
Constructor
- Parameters
-
| threadName | The name of the thread for debugging. |
| maxQueueSize | The maximum number of messages allowed in the queue. 0 means unlimited (no back pressure). |
◆ ~Thread() [2/2]
◆ CreateThread() [1/2]
| bool Thread::CreateThread |
( |
| ) |
|
Called once to create the worker thread
- Returns
- TRUE if thread is created. FALSE otherwise.
◆ CreateThread() [2/2]
| 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 otherise.
◆ DispatchDelegate() [1/2]
Dispatch and invoke a delegate target on the destination thread.
- Parameters
-
| [in] | msg | - Delegate message containing target function arguments. |
Implements dmq::IThread.
◆ DispatchDelegate() [2/2]
| 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] | msg | A shared pointer to the delegate message. This pointer must remain valid until the target thread finishes execution. |
Implements dmq::IThread.
◆ ExitThread() [1/2]
| void Thread::ExitThread |
( |
| ) |
|
Terminate the thread gracefully.
◆ ExitThread() [2/2]
| void Thread::ExitThread |
( |
| ) |
|
Called once at program exit to shut down the worker thread.
◆ GetCurrentThreadId() [1/2]
| std::thread::id Thread::GetCurrentThreadId |
( |
| ) |
|
|
static |
Get the ID of the currently executing thread.
◆ GetCurrentThreadId() [2/2]
| static std::thread::id Thread::GetCurrentThreadId |
( |
| ) |
|
|
static |
Get the ID of the currently executing thread.
◆ GetQueueSize()
| size_t Thread::GetQueueSize |
( |
| ) |
|
Get size of thread message queue.
◆ GetThreadId() [1/2]
| std::thread::id Thread::GetThreadId |
( |
| ) |
|
Get the ID of this thread instance.
◆ GetThreadId() [2/2]
| std::thread::id Thread::GetThreadId |
( |
| ) |
|
Get the ID of this thread instance.
◆ GetThreadName() [1/2]
| std::string Thread::GetThreadName |
( |
| ) |
|
|
inline |
◆ GetThreadName() [2/2]
| std::string Thread::GetThreadName |
( |
| ) |
|
|
inline |
The documentation for this class was generated from the following files: