34#include <condition_variable>
40 bool operator()(
const std::shared_ptr<ThreadMsg>& a,
const std::shared_ptr<ThreadMsg>& b)
const {
41 return static_cast<int>(a->GetPriority()) <
static_cast<int>(b->GetPriority());
55 Thread(
const std::string& threadName,
size_t maxQueueSize = 0);
64 bool CreateThread(std::optional<dmq::Duration> watchdogTimeout = std::nullopt);
96 void SetThreadName(std::thread::native_handle_type handle,
const std::string& name);
102 void WatchdogCheck();
110 std::optional<std::thread> m_thread;
112 std::priority_queue<std::shared_ptr<ThreadMsg>,
116 std::priority_queue<std::shared_ptr<ThreadMsg>,
117 std::vector<std::shared_ptr<ThreadMsg>>,
121 std::condition_variable m_cv;
124 std::condition_variable m_cvNotFull;
126 const std::string THREAD_NAME;
129 const size_t MAX_QUEUE_SIZE;
132 std::optional<std::promise<void>> m_threadStartPromise;
133 std::optional<std::future<void>> m_threadStartFuture;
135 std::atomic<bool> m_exit;
138 std::atomic<dmq::TimePoint> m_lastAliveTime;
139 std::unique_ptr<Timer> m_watchdogTimer;
141 std::unique_ptr<Timer> m_threadTimer;
143 std::atomic<dmq::Duration> m_watchdogTimeout;
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 stdlib/Thread.h:79
virtual void DispatchDelegate(std::shared_ptr< dmq::DelegateMsg > msg)
std::thread::id GetThreadId()
Get the ID of this thread instance.
static std::thread::id GetCurrentThreadId()
Get the ID of the currently executing thread.
virtual bool IsCurrentThread() override
Returns true if the calling thread is this thread.
bool CreateThread()
Definition cmsis-rtos2/Thread.cpp:42
Thread(const std::string &threadName, size_t maxQueueSize=0)
size_t GetQueueSize()
Get size of thread message queue.
Definition stdlib/Thread.cpp:107
void ExitThread()
Called once at program exit to shut down the worker thread.
A base class for a delegate enabled execution thread. Implemented by application code if asynchronous...
Definition IThread.h:22
RAII handle to a single Signal subscription. Disconnects automatically on destruction....
Definition Signal.h:104
Definition stl_allocator.h:29
Definition stdlib/Thread.h:39
bool operator()(const std::shared_ptr< ThreadMsg > &a, const std::shared_ptr< ThreadMsg > &b) const
Definition stdlib/Thread.h:40