Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.

Add EVENTS_EVENT_SIZE define for calculated queue allocations #8

Merged
merged 3 commits into from
Jul 30, 2016

Conversation

geky
Copy link
Contributor

@geky geky commented Jul 28, 2016

In the mbed-events library, the structure of an event is correctly hidden from the public api. Unfortunately, this makes it difficult to calculate the space needed for a finite-set of events.

In this pr, EVENTS_EVENT_SIZE is defined as the space needed for a single Callback<void()> event.

This allows queues to be created with the exact size required for Callback<void()> or any callback with a single word of associated context:

EventQueue queue(12 * EVENTS_EVENT_SIZE);

For events with different sized contexts, the exact size can still be calculated, although it is quite a bit uglier. This should be less common than Callback<void()>, and was shown in previous versions to be difficult to reason about when compared to raw buffer sizes:

EventQueue queue(12 * (EVENTS_EVENT_SIZE+sizeof(PacketFunctor)-sizeof(Callback<void()>)));

geky added 3 commits July 28, 2016 02:59
In the events library, the structure of an event is correctly not
part of the public api. Unfortunately, this makes it difficult to
calculate the space needed for a finite set of events.

EVENTS_EVENT_SIZE is defined as the space needed for the smallest
event, the event allocated in event_call.

This allows queues to be created based on a number of events:
equeue_create(&q, 12 * (EVENTS_EVENT_SIZE+sizeof(struct context)));
Add EVENTS_EVENT_SIZE define for calculated queue allocations
Adjusted to account for size of Callback, which is a bit larger
than an average C callback due to type information and member
function pointers.
@geky geky merged commit 7c44753 into master Jul 30, 2016
@geky geky deleted the event-size branch July 30, 2016 00:47
geky added a commit that referenced this pull request Aug 8, 2016
Add set of event queue composition functions
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant