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

EventQueue should permit static allocation #9172

Closed
kjbracey opened this issue Dec 20, 2018 · 5 comments
Closed

EventQueue should permit static allocation #9172

kjbracey opened this issue Dec 20, 2018 · 5 comments

Comments

@kjbracey
Copy link
Contributor

kjbracey commented Dec 20, 2018

Description

EventQueue and Event always require an allocation to perform a call or call_in, meaning it can fail.

This is potentially fatal for state machines - there is no plan B if the queue fails.

There should be an alternative form that allows the storage for the struct equeue_event to be static, so the call cannot fail.

An analogous mechanism is provided in Nanostack's eventOS_event.h: eventOS_event_send_user_allocated.

I had previously thought that the equeue allocation mechanism and the dispatch mechanism were inherently coupled, meaning this would require an involved rework, but I now think that isn't the case. All the dispatching is just based on a linked list, no?

Looking at the API, it seems to me that we have a ready-made answer. Event could store the struct equeue_event as a member, rather than a pointer to one it allocates from the queue. It appears the existing API would fully support that - the equeue_event has the same lifetime as the Event, and its size is can be calculated at compile time from the templating.

It almost seems as if Event was made for this purpose...

Issue request type

[ ] Question
[X] Enhancement
[ ] Bug
@kjbracey
Copy link
Contributor Author

Staring a bit harder, I see that Event is intended to function as a shared pointer onto the equeue_event, but that functionality is quite separate.

Seems like it could be split so that effectively Event is a SharedPtr<EventObject> with the necessary operator()/post/call.

@kjbracey kjbracey changed the title EventQueue should permit user allocation EventQueue should permit static allocation Dec 20, 2018
@ciarmcom
Copy link
Member

Internal Jira reference: https://jira.arm.com/browse/MBOCUSTRIA-352

@bulislaw
Copy link
Member

bulislaw commented Feb 5, 2019

@kjbracey-arm could you file it as a PREQ? I think it's very important our scheduler/event-loop doesn't rely on dynamic memory. It's just yet another thing that can go wrong.

@ciarmcom
Copy link
Member

Thank you for raising this issue. Please note we have updated our policies and
now only defects should be raised directly in GitHub. Going forward questions and
enhancements will be considered in our forums, https://forums.mbed.com/ . If this
issue is still relevant please re-raise it there.
This GitHub issue will now be closed.

@kjbracey
Copy link
Contributor Author

kjbracey commented Nov 1, 2019

For the record, this feature was implemented by #11342

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

No branches or pull requests

4 participants