From 5d7573e51382864cfabbb050b30df5ce89943c2d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 20 Jul 2025 11:05:44 +0100 Subject: [PATCH] Minor changes --- include/etl/callback_timer_deferred_locked.h | 70 +++++++++++-------- test/CMakeLists.txt | 2 +- test/syntax_check/CMakeLists.txt | 1 + .../callback_timer_deferred_locked.h.t.cpp | 29 ++++++++ test/test_callback_timer_deferred_locked.cpp | 3 +- test/vs2022/etl.vcxproj | 20 ++++++ 6 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 test/syntax_check/callback_timer_deferred_locked.h.t.cpp diff --git a/include/etl/callback_timer_deferred_locked.h b/include/etl/callback_timer_deferred_locked.h index 10469978..9e9dd9d6 100644 --- a/include/etl/callback_timer_deferred_locked.h +++ b/include/etl/callback_timer_deferred_locked.h @@ -5,7 +5,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2021 John Wellbelove +Copyright(c) 2025 John Wellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -35,7 +35,6 @@ SOFTWARE. #include "priority_queue.h" #include "delegate.h" - namespace etl { //*************************************************************************** @@ -54,15 +53,22 @@ namespace etl typedef icallback_timer_locked::unlock_type unlock_type; private: - class CallbackNode { - public: - callback_type callback; - uint_least8_t priority; - 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 - } + + 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; }; public: @@ -83,8 +89,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) @@ -145,24 +152,27 @@ namespace etl //******************************************* void handle_deferred(void) { - callback_type work_todo_callback; - do - { - lock(); - if (handler_queue.empty()) - { - work_todo_callback.clear(); - } - else - { - CallbackNode &work_todo_callback_node = handler_queue.top(); - work_todo_callback = work_todo_callback_node.callback; - handler_queue.pop(); - } - unlock(); + callback_type work_todo_callback; - work_todo_callback.call_if(); - }while (work_todo_callback.is_valid()); + do + { + lock(); + + if (handler_queue.empty()) + { + work_todo_callback.clear(); + } + else + { + CallbackNode &work_todo_callback_node = handler_queue.top(); + work_todo_callback = work_todo_callback_node.callback; + handler_queue.pop(); + } + + unlock(); + + work_todo_callback.call_if(); + } while (work_todo_callback.is_valid()); } // Overloads diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a7996917..64d11735 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -54,9 +54,9 @@ add_executable(etl_tests test_callback_service.cpp test_callback_timer.cpp test_callback_timer_atomic.cpp + test_callback_timer_deferred_locked.cpp test_callback_timer_interrupt.cpp test_callback_timer_locked.cpp - test_callback_timer_deferred_locked.cpp test_const_map.cpp test_const_map_constexpr.cpp test_const_multimap.cpp diff --git a/test/syntax_check/CMakeLists.txt b/test/syntax_check/CMakeLists.txt index 6892d139..62d864c9 100644 --- a/test/syntax_check/CMakeLists.txt +++ b/test/syntax_check/CMakeLists.txt @@ -92,6 +92,7 @@ target_sources(tests PRIVATE callback_service.h.t.cpp callback_timer.h.t.cpp callback_timer_atomic.h.t.cpp + callback_timer_deferred_locked.h.t.cpp callback_timer_interrupt.h.t.cpp callback_timer_locked.h.t.cpp char_traits.h.t.cpp diff --git a/test/syntax_check/callback_timer_deferred_locked.h.t.cpp b/test/syntax_check/callback_timer_deferred_locked.h.t.cpp new file mode 100644 index 00000000..deef197a --- /dev/null +++ b/test/syntax_check/callback_timer_deferred_locked.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/test_callback_timer_deferred_locked.cpp b/test/test_callback_timer_deferred_locked.cpp index b95f6083..591cf732 100644 --- a/test/test_callback_timer_deferred_locked.cpp +++ b/test/test_callback_timer_deferred_locked.cpp @@ -5,7 +5,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2021 John Wellbelove +Copyright(c) 2025 John Wellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -255,6 +255,7 @@ namespace CHECK_EQUAL(0U, locks.lock_count); } + //************************************************************************* TEST(callback_timer_deferred_locked_one_shot_priority) { locks.clear(); diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index f13f43b9..8395d3b2 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3283,6 +3283,7 @@ + @@ -4642,6 +4643,24 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true true @@ -9272,6 +9291,7 @@ +