-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys/xtimer: use thread flags for xtimer_msg_receive_timeout() #13429
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
sys/xtimer: use thread flags for xtimer_msg_receive_timeout() #13429
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be possible to do this with a mutex so we don't require the thread flags feature?
res = -1; | ||
} | ||
|
||
if (! (flags & THREAD_FLAG_TIMEOUT)) { | ||
xtimer_remove(t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. the timer could fire between the check and calling the remove, leaving a TIMEOUT flag set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that matters, as the "timeout set" functions always clear that flag at the beginning. I'll clear it anyways.
I think not without going into the guts of the message receive code. thread flags already have special handling in there, that's why I've re-used it. |
I wonder how safe is it to assume that the timeout thread flag is not used by any other callback/interrupt? An alternative to this solution could be adding a mutex that is (try_)locked either from |
@@ -128,47 +128,44 @@ void _xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_ | |||
_xtimer_set64(timer, offset, offset >> 32); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is:
_callback_msg
_setup_msg
_xtimer_set_msg
_xtimer_set_msg64
still needed?
It would then require the mutex feature. That isn't optional, but still quite large and not necesarily used (linked in). |
That is actually a feature, and a matter of documentation.
Now the xtimer_msg_receive calls can each take up to 5s, but with the timeout flag based implementation, the whole block cannot take longer than 10s. But yeah, for that to work the timeout flag shouldn't be reset in |
How to continue with this one? This solution is better than what we have now but I have the strong feeling someone will be bitten by this again If we try to "fix" the corner cases by documentation. |
This is also pretty old, is it still a problem now? |
closing as xtimer is deprecated |
Contribution description
This changes xtimer_msg_receive_timeout() to use thread flags instead of a canary message, for the timeout. This is one way to fix the issue found in #13345.
It does add a dependency to "core_thread_flags", adding ~200b code on ARM, if thread flags are otherwise unused.
Testing procedure
Fixes 13345.
Issues/PRs references