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

event_periodic_callback: add getter for user context, one-shot event #18656

Merged
merged 3 commits into from
Oct 4, 2022

Conversation

benpicco
Copy link
Contributor

@benpicco benpicco commented Sep 27, 2022

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_dev that 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.arg which 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

@benpicco benpicco added the Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer label Sep 27, 2022
@github-actions github-actions bot added the Area: sys Area: System label Sep 27, 2022
@benpicco benpicco requested a review from maribu September 27, 2022 12:50
@benpicco benpicco changed the title event_periodic_callback: add getter for user context event_periodic_callback: add getter for user context, one-shot event Sep 27, 2022
@github-actions github-actions bot added the Area: tests Area: tests and testing framework label Sep 27, 2022
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 28, 2022
Comment on lines +49 to +52
static inline void *event_periodic_callback_get_arg(event_periodic_callback_t *event)
{
return event->event.arg;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I wanted to not expose the internal event struct to the user, they should only deal with event_periodic_callback_t

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 4, 2022
@benpicco benpicco enabled auto-merge October 4, 2022 14:58
@benpicco benpicco merged commit 161172c into RIOT-OS:master Oct 4, 2022
@benpicco benpicco deleted the event_periodic_callback_get_arg branch October 5, 2022 09:37
@maribu maribu added this to the Release 2022.10 milestone Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants