event_periodic_callback: add getter for user context, one-shot event#18656
Merged
benpicco merged 3 commits intoRIOT-OS:masterfrom Oct 4, 2022
Merged
event_periodic_callback: add getter for user context, one-shot event#18656benpicco merged 3 commits intoRIOT-OS:masterfrom
benpicco merged 3 commits intoRIOT-OS:masterfrom
Conversation
maribu
approved these changes
Oct 4, 2022
Comment on lines
+49
to
+52
| static inline void *event_periodic_callback_get_arg(event_periodic_callback_t *event) | ||
| { | ||
| return event->event.arg; | ||
| } |
Member
There was a problem hiding this comment.
To me,
- arg = ev->event.arg;
+ arg = event_periodic_callback_get_arg(ev);does not feel too much of a win. But it may provide some flexibility for future refactoring.
Contributor
Author
There was a problem hiding this comment.
Yea I wanted to not expose the internal event struct to the user, they should only deal with event_periodic_callback_t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
event_periodic_callback_get_arg()This is a purely aesthetic addition: When initializing an event, e.g. to measure a sensor, I want to have a locally visible
static lm75_t lm75_devthat I use as the event argument.I can access this in the callback, but if I want to access it outside the callback, e.g. to re-init the sensor after the callback was suspended, I have to access
event->event.argwhich feels dirty.Instead, add a nice getter function that does the same.
event_callback_oneshot()An easy helper to execute a function by the event thread, to be called e.g. in an interrupt or by another function that is not supposed to block.
Testing procedure
Issues/PRs references