DelegateMQ
Loading...
Searching...
No Matches
freertos/Thread.h
Go to the documentation of this file.
1#ifndef _THREAD_FREERTOS_H
2#define _THREAD_FREERTOS_H
3
24
25#include "delegate/IThread.h"
26#include "FreeRTOS.h"
27#include "task.h"
28#include "queue.h"
29#include "semphr.h"
30#include <string>
31#include <memory>
32
33class ThreadMsg;
34
35class Thread : public dmq::IThread
36{
37public:
39 static const size_t DEFAULT_QUEUE_SIZE = 20;
40
44 Thread(const std::string& threadName, size_t maxQueueSize = 0);
45
48
52
54 void ExitThread();
55
57 TaskHandle_t GetThreadId();
58
60 static TaskHandle_t GetCurrentThreadId();
61
63 std::string GetThreadName() { return THREAD_NAME; }
64
68 void SetThreadPriority(int priority);
69
73 void SetStackMem(StackType_t* stackBuffer, uint32_t stackSizeInWords);
74
75 // IThread Interface Implementation
76 virtual void DispatchDelegate(std::shared_ptr<dmq::DelegateMsg> msg) override;
77
78private:
79 Thread(const Thread&) = delete;
80 Thread& operator=(const Thread&) = delete;
81
83 static void Process(void* instance);
84
85 // Run loop called by Process
86 void Run();
87
88 TaskHandle_t m_thread = nullptr;
89 QueueHandle_t m_queue = nullptr;
90 SemaphoreHandle_t m_exitSem = nullptr; // Synchronization for safe destruction
91
92 const std::string THREAD_NAME;
93 size_t m_queueSize;
94 int m_priority;
95
96 // Static allocation support
97 StackType_t* m_stackBuffer = nullptr;
98 uint32_t m_stackSize = 1024; // Default size (words)
99 StaticTask_t m_tcb; // TCB storage for static creation
100};
101
102#endif
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 freertos/Thread.h:63
TaskHandle_t GetThreadId()
Get the ID of this thread instance.
~Thread()
Destructor.
void SetStackMem(StackType_t *stackBuffer, uint32_t stackSizeInWords)
Definition freertos/Thread.cpp:36
virtual void DispatchDelegate(std::shared_ptr< dmq::DelegateMsg > msg) override
Enqueues a delegate message for execution on this thread.
static TaskHandle_t GetCurrentThreadId()
Get the ID of the currently executing 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