igor-krechetov / hsmcpp

C++ based Hierarchical / Finite State Machine library oriented for embedded and RTOS systems.
https://hsmcpp.readthedocs.io
MIT License
69 stars 11 forks source link

Fix expiration time of timer being restarted #9

Closed wiktorpi closed 8 months ago

wiktorpi commented 11 months ago

Solution to the issue presented in This PR

I had a bit of time and found the issue. If a timer expires, intervalMs, is <= 0. Then, the restarted timer will have a elapseAfter of now plus at most zero, therefore making it immediately expired. Then, the situation continues in the next timer thread loop, and as intervalMs is zero or less, the condition variable wait also immediately returns. This results in uncontrolled triggering of timer callbacks.

igor-krechetov commented 11 months ago

Hello @wiktorpi . Thank you for your positive feedback and also taking time to actually debug it! I'll add your use-case to unit tests and will merge your fix after testing.

igor-krechetov commented 8 months ago

Hi @wiktorpi , Thank you for finding time and making the fix. Unfortunately after debugging this further I found out that it introduces another issue so I had to fix it in another way.

The bug was fixed with commit a9a5b002219a64ae3608e43b82b11eaeaaf2e914 (version 1.0.1) so I'm closing this PR.