Skip to content

Fix periodic timers firing only once #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michael-p
Copy link
Contributor

Creating a Timer with auto_reload set to true (the default) results in the timer callback being invoked just once, not periodic.

The problem is that the Drop implementation of Timer stops the timer, and since the timer_callback function constructs a Timer out of thin air and passes that by value to the timer callback Box<dyn Fn(Timer)> the timer gets dropped when the callback ends and stops. Relevant code: https://github.com/lobaro/FreeRTOS-rust/blob/master/freertos-rust/src/timers.rs#L120

This was introduced in #57. Previously, Timer had a detached flag that prevented it from being stopped in its destructor in this situation. Instead of trying to revert this this PR changes the API so that timer callbacks get passed in the Timer by reference. I think this makes more sense than giving ownership of the timer to its own callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant