DelegateMQ
Loading...
Searching...
No Matches
threadx/Thread.h
Go to the documentation of this file.
1#ifndef _THREAD_THREADX_H
2#define _THREAD_THREADX_H
3
23
24#include "delegate/IThread.h"
25#include "tx_api.h"
26#include <string>
27#include <memory>
28#include <vector>
29
30class ThreadMsg;
31
32class Thread : public dmq::IThread
33{
34public:
36 static const ULONG DEFAULT_QUEUE_SIZE = 20;
37
41 Thread(const std::string& threadName, size_t maxQueueSize = 0);
42
45
49
51 void ExitThread();
52
54 TX_THREAD* GetThreadId();
55
57 static TX_THREAD* GetCurrentThreadId();
58
61 void SetThreadPriority(UINT priority);
62
65
67 std::string GetThreadName() { return THREAD_NAME; }
68
69 // IThread Interface Implementation
70 virtual void DispatchDelegate(std::shared_ptr<dmq::DelegateMsg> msg) override;
71
72private:
73 Thread(const Thread&) = delete;
74 Thread& operator=(const Thread&) = delete;
75
77 static void Process(ULONG instance);
78
79 // Run loop called by Process
80 void Run();
81
82 // ThreadX Control Blocks
83 TX_THREAD m_thread;
84 TX_QUEUE m_queue;
85 TX_SEMAPHORE m_exitSem; // Semaphore to signal thread completion
86
87 // Memory buffers required by ThreadX (Managed by RAII)
88 // Using ULONG[] ensures correct alignment for ThreadX stacks and queues
89 std::unique_ptr<ULONG[]> m_stackMemory;
90 std::unique_ptr<ULONG[]> m_queueMemory;
91
92 const std::string THREAD_NAME;
93
94 // Configurable stack size (bytes)
95 static const ULONG STACK_SIZE = 2048;
96
97 size_t m_queueSize; // Stored queue size
98 UINT m_priority; // Stored priority
99};
100
101#endif // _THREAD_THREADX_H
Interface for cross-thread delegate dispatching.
Cross-platform thread for any system supporting C++11 std::thread (e.g. Windows, Linux).
Definition cmsis-rtos2/Thread.h:33
std::string GetThreadName()
Get thread name.
Definition threadx/Thread.h:67
TX_THREAD * GetThreadId()
Get the ID of this thread instance.
UINT GetThreadPriority()
Get current priority.
static TX_THREAD * GetCurrentThreadId()
Get the ID of the currently executing thread.
~Thread()
Destructor.
virtual void DispatchDelegate(std::shared_ptr< dmq::DelegateMsg > msg) override
Enqueues a delegate message for execution on this thread.
static const uint32_t DEFAULT_QUEUE_SIZE
Default queue size if 0 is passed.
Definition cmsis-rtos2/Thread.h:36
void SetThreadPriority(osPriority_t priority)
Definition cmsis-rtos2/Thread.cpp:71
bool CreateThread()
Thread(const std::string &threadName, size_t maxQueueSize=0)
void ExitThread()
Terminate the thread gracefully.
A class to hold a platform-specific thread messsage that will be passed through the OS message queue.
Definition cmsis-rtos2/ThreadMsg.h:12
A base class for a delegate enabled execution thread. Implemented by application code if asynchronous...
Definition IThread.h:22