Minor changes

This commit is contained in:
John Wellbelove 2025-07-20 11:05:44 +01:00
parent 42677dd9ee
commit 5d7573e513
6 changed files with 93 additions and 32 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <etl/callback_timer_deferred_locked.h>

View File

@ -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();

View File

@ -3283,6 +3283,7 @@
<ClInclude Include="..\..\include\etl\byte_stream.h" />
<ClInclude Include="..\..\include\etl\callback_timer.h" />
<ClInclude Include="..\..\include\etl\callback_timer_atomic.h" />
<ClInclude Include="..\..\include\etl\callback_timer_deferred_locked.h" />
<ClInclude Include="..\..\include\etl\callback_timer_interrupt.h" />
<ClInclude Include="..\..\include\etl\callback_timer_locked.h" />
<ClInclude Include="..\..\include\etl\chrono.h" />
@ -4642,6 +4643,24 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03 - No virtual messages|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\syntax_check\callback_timer_deferred_locked.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual imessage|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++ 20 - No Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++23 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++23|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - No STL - Optimised -O2|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03 - No virtual messages|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - Optimised O2|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual messages|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\syntax_check\callback_timer_interrupt.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++23|Win32'">true</ExcludedFromBuild>
@ -9272,6 +9291,7 @@
<ClCompile Include="..\test_byte_stream.cpp" />
<ClCompile Include="..\test_callback_service.cpp" />
<ClCompile Include="..\test_callback_timer_atomic.cpp" />
<ClCompile Include="..\test_callback_timer_deferred_locked.cpp" />
<ClCompile Include="..\test_callback_timer_interrupt.cpp" />
<ClCompile Include="..\test_callback_timer_locked.cpp" />
<ClCompile Include="..\test_char_traits.cpp" />