Skip to content
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

Incorrect implementation of is_oneshot() in trait Timer in kernel::hil::time #2018

Closed
lebakassemmerl opened this issue Jul 13, 2020 · 5 comments · Fixed by #2025
Closed

Incorrect implementation of is_oneshot() in trait Timer in kernel::hil::time #2018

lebakassemmerl opened this issue Jul 13, 2020 · 5 comments · Fixed by #2025

Comments

@lebakassemmerl
Copy link
Contributor

As I was trying to implement the Timer trait from kernel::hil::time, I noticed that the function is_oneshot() is probably not correctly implemented.
The current implementation is the following one:

/// Returns whether this is a oneshot (rather than repeating) timer.
fn is_oneshot(&self) -> bool {
    self.interval().is_none()
}

However, the function inverval() says that it can return None if the timer is configured as oneshot-timer OR if the timer is disabled:

/// Returns the interval for a repeating timer.
///
/// Returns `None` if the timer is disabled or in oneshot mode and `Some(interval)` if it is
/// repeating.
fn interval(&self) -> Option<W>;

So I think a correct implementation would be something like this:

fn is_oneshot(&self) -> bool {
    self.interval().is_none() && self.is_enabled()
}

Am I right on this?

@hudson-ayers
Copy link
Contributor

You are right that the existing implementation is incorrect, and I think your correct implementation looks right as well.

@lebakassemmerl
Copy link
Contributor Author

Ok!
Should I open a PR for this issue?

@hudson-ayers
Copy link
Contributor

A PR would be welcome! There are ongoing efforts to revamp the alarm and timer traits, but they may not land in master for some time, so getting this fix in now would be great.

@lebakassemmerl
Copy link
Contributor Author

I have opened an PR now, should I close this issue?

@hudson-ayers hudson-ayers linked a pull request Jul 15, 2020 that will close this issue
1 task
@hudson-ayers
Copy link
Contributor

I linked the PR, when it is merged this issue will be closed!

@bors bors bot closed this as completed in #2025 Jul 15, 2020
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 a pull request may close this issue.

2 participants