DelegateMQ
Loading...
Searching...
No Matches
cmsis-rtos2/Thread.h
Go to the documentation of this file.
1#ifndef _THREAD_CMSIS_RTOS2_H
2#define _THREAD_CMSIS_RTOS2_H
3
24
25#include "delegate/IThread.h"
26#include "cmsis_os2.h"
27#include <string>
28#include <memory>
29
30class ThreadMsg;
31
32class Thread : public dmq::IThread
33{
34public:
36 static const uint32_t DEFAULT_QUEUE_SIZE = 20;
37
41 Thread(const std::string& threadName, size_t maxQueueSize = 0);
42
43 ~Thread();
44
45 bool CreateThread();
46 void ExitThread();
47
48 osThreadId_t GetThreadId();
49 static osThreadId_t GetCurrentThreadId();
50
53 void SetThreadPriority(osPriority_t priority);
54
56 osPriority_t GetThreadPriority();
57
58 std::string GetThreadName() { return THREAD_NAME; }
59
60 virtual void DispatchDelegate(std::shared_ptr<dmq::DelegateMsg> msg) override;
61
62private:
63 Thread(const Thread&) = delete;
64 Thread& operator=(const Thread&) = delete;
65
66 // Entry point
67 static void Process(void* argument);
68 void Run();
69
70 osThreadId_t m_thread = NULL;
71 osMessageQueueId_t m_msgq = NULL;
72 osSemaphoreId_t m_exitSem = NULL; // Semaphore to signal thread completion
73
74 const std::string THREAD_NAME;
75
76 // Configurable sizes
77 static const uint32_t STACK_SIZE = 2048; // Bytes
78
79 size_t m_queueSize;
80 osPriority_t m_priority;
81};
82
83#endif // _THREAD_CMSIS_RTOS2_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()
Definition cmsis-rtos2/Thread.h:58
osPriority_t GetThreadPriority()
Get current priority.
Definition cmsis-rtos2/Thread.cpp:84
~Thread()
Definition cmsis-rtos2/Thread.cpp:29
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()
Definition cmsis-rtos2/Thread.cpp:42
Thread(const std::string &threadName, size_t maxQueueSize=0)
Definition cmsis-rtos2/Thread.cpp:16
void ExitThread()
Definition cmsis-rtos2/Thread.cpp:92
osThreadId_t GetThreadId()
Definition cmsis-rtos2/Thread.cpp:132
static osThreadId_t GetCurrentThreadId()
Definition cmsis-rtos2/Thread.cpp:140
virtual void DispatchDelegate(std::shared_ptr< dmq::DelegateMsg > msg) override
Enqueues a delegate message for execution on this thread.
Definition qt/Thread.cpp:93
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