From da5e42a4bc0eb64be3e2adfcc996302cd24c3ab6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 12 Sep 2025 12:48:18 +0100 Subject: [PATCH] Moved and renamed common class to base --- include/etl/callback_timer_deferred_locked.h | 23 +++------------- include/etl/callback_timer_locked.h | 29 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/include/etl/callback_timer_deferred_locked.h b/include/etl/callback_timer_deferred_locked.h index b8546ef7..ce760648 100644 --- a/include/etl/callback_timer_deferred_locked.h +++ b/include/etl/callback_timer_deferred_locked.h @@ -54,22 +54,7 @@ namespace etl private: - class CallbackNode - { - public: - - CallbackNode(callback_type &callback_,uint_least8_t priority_) : callback(callback_), priority(priority_) - { - } - - bool operator < (const CallbackNode& p) const - { - return this->priority > p.priority; // comparison was inverted here to easy the code design - } - - callback_type callback; - uint_least8_t priority; - }; + typedef icallback_timer_locked::callback_node callback_node; public: @@ -117,7 +102,7 @@ namespace etl { if (!handler_queue.full()) { - handler_queue.push(CallbackNode(timer.callback, timer_priorities[timer.id])); + handler_queue.push(callback_node(timer.callback, timer_priorities[timer.id])); } } @@ -167,7 +152,7 @@ namespace etl } else { - CallbackNode &work_todo_callback_node = handler_queue.top(); + callback_node &work_todo_callback_node = handler_queue.top(); work_todo_callback = work_todo_callback_node.callback; handler_queue.pop(); } @@ -213,7 +198,7 @@ namespace etl private: - priority_queue handler_queue; + priority_queue handler_queue; uint_least8_t timer_priorities[Max_Timers_]; timer_data timer_array[Max_Timers_]; }; diff --git a/include/etl/callback_timer_locked.h b/include/etl/callback_timer_locked.h index ff2837c5..75689634 100644 --- a/include/etl/callback_timer_locked.h +++ b/include/etl/callback_timer_locked.h @@ -355,6 +355,23 @@ namespace etl protected: + class callback_node + { + public: + + callback_node(callback_type &callback_,uint_least8_t priority_) : callback(callback_), priority(priority_) + { + } + + bool operator < (const callback_node& p) const + { + return this->priority > p.priority; // comparison was inverted here to easy the code design + } + + callback_type callback; + uint_least8_t priority; + }; + //************************************************************************* /// The configuration of a timer. struct timer_data @@ -642,6 +659,7 @@ namespace etl event_callback_type remove_callback; public: + template friend class callback_timer_locked; @@ -666,6 +684,12 @@ namespace etl typedef icallback_timer_locked::lock_type lock_type; typedef icallback_timer_locked::unlock_type unlock_type; + private: + + typedef icallback_timer_locked::callback_node callback_node; + + public: + //******************************************* /// Constructor. //******************************************* @@ -683,8 +707,9 @@ namespace etl this->set_locks(try_lock_, lock_, unlock_); } - // Implement virtual functions - + //******************************************* + /// Handle the tick call + //******************************************* bool tick(uint32_t count) final { if (enabled)