ARMmbed / mbed-events

DEPRECATED! This project has moved to mbed-os
https://github.com/ARMmbed/mbed-os/tree/master/events
Apache License 2.0
11 stars 6 forks source link

Add EVENTS_EVENT_SIZE define for calculated queue allocations #8

Closed geky closed 8 years ago

geky commented 8 years ago

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()>)));