From ef2b5e47b19f9b87fbeb705dd8713e6779cf5bb5 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 8 Jul 2025 07:46:12 -0400 Subject: [PATCH] MT#63171 introduce AmEventQueueThread New class inheriting from AmEventQueueBase to be used in threads that run in a loop processing events until thread shutdown is requested. Change-Id: Ib63837997659a944fc217712ff2472c7900e7525 --- core/AmEventQueue.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/AmEventQueue.h b/core/AmEventQueue.h index 167c768b..e76aa979 100644 --- a/core/AmEventQueue.h +++ b/core/AmEventQueue.h @@ -118,5 +118,32 @@ public: AmEventQueue(AmEventHandler* handler) : AmEventQueueBase(handler, _mut, _cond) {} }; +/** + * \brief Thread-based asynchronous event queue + * + * This class can be used to run a thread based on an event + * queue. + */ +class AmEventQueueThread + : public AmThread, + public AmEventQueueBase +{ +protected: + // mutex must be held + bool shouldSleep() const { + return !stop_requested_unlocked() && AmEventQueueBase::shouldSleep(); + } + +public: + AmEventQueueThread(AmEventHandler* handler) + : AmEventQueueBase(handler, run_mut, run_cond) + {} + + virtual void on_destroy() { + stop(); + join(); + } +}; + #endif