Miosix  2.0alpha1
miosix::FixedEventQueue< NumSlots, SlotSize > Class Template Reference

#include <e20.h>

Inheritance diagram for miosix::FixedEventQueue< NumSlots, SlotSize >:
Collaboration diagram for miosix::FixedEventQueue< NumSlots, SlotSize >:

Public Member Functions

 FixedEventQueue ()
 
void post (Callback< SlotSize > event)
 
bool postNonBlocking (Callback< SlotSize > event)
 
bool IRQpost (Callback< SlotSize > event)
 
bool IRQpost (Callback< SlotSize > event, bool &hppw)
 
void run ()
 
void runOne ()
 
unsigned int size () const
 
unsigned int empty () const
 

Detailed Description

template<unsigned NumSlots, unsigned SlotSize = 20>
class miosix::FixedEventQueue< NumSlots, SlotSize >

A fixed size event queue.

This guarantees it makes no use of the heap, therefore events can be posted also from within interrupt handlers. This simplifies the development of device drivers.

This class acts as a synchronization point, multiple threads (and IRQs) can post events, and multiple threads can call run() or runOne() (thread pooling).

Events are function that are posted by a thread through post() but executed in the context of the thread that calls run() or runOne()

Parameters
NumSlotsmaximum queue length
SlotSizesize of the Callback objects. This limits the maximum number of parameters that can be bound to a function. If you get compile-time errors in callback.h, consider increasing this value. The default is 20 bytes, which is enough to bind a member function pointer, a "this" pointer and two byte or pointer sized parameters.

Constructor & Destructor Documentation

template<unsigned NumSlots, unsigned SlotSize = 20>
miosix::FixedEventQueue< NumSlots, SlotSize >::FixedEventQueue ( )
inline

Constructor.

Member Function Documentation

template<unsigned NumSlots, unsigned SlotSize = 20>
unsigned int miosix::FixedEventQueue< NumSlots, SlotSize >::empty ( ) const
inline
Returns
true if the queue has no events
template<unsigned NumSlots, unsigned SlotSize = 20>
bool miosix::FixedEventQueue< NumSlots, SlotSize >::IRQpost ( Callback< SlotSize >  event)
inline

Post an event in the queue, or return if the queue was full. Can be called only with interrupts disabled or within an interrupt handler, allowing device drivers to post an event to a thread.

Parameters
eventfunction function to be called in the thread that calls run() or runOne(). Bind can be used to bind parameters to the function. Unlike with the EventQueue, the operator= of the bound parameters have the restriction that they need to be callable with interrupts disabled so they must not open files, print, ...

If the call is made from within an InterruptDisableLock the copy constructors can allocate memory, while if the call is made from an interrupt handler or a FastInterruptFisableLock memory allocation is forbidden.

Returns
false if there was no space in the queue
template<unsigned NumSlots, unsigned SlotSize = 20>
bool miosix::FixedEventQueue< NumSlots, SlotSize >::IRQpost ( Callback< SlotSize >  event,
bool &  hppw 
)
inline

Post an event in the queue, or return if the queue was full. Can be called only with interrupts disabled or within an interrupt handler, allowing device drivers to post an event to a thread.

Parameters
eventfunction function to be called in the thread that calls run() or runOne(). Bind can be used to bind parameters to the function. Unlike with the EventQueue, the operator= of the bound parameters have the restriction that they need to be callable with interrupts disabled so they must not open files, print, ...

If the call is made from within an InterruptDisableLock the copy constructors can allocate memory, while if the call is made from an interrupt handler or a FastInterruptFisableLock memory allocation is forbidden.

Parameters
hppwreturns true if a higher priority thread was awakened as part of posting the event. Can be used inside an IRQ to call the scheduler.
Returns
false if there was no space in the queue
template<unsigned NumSlots, unsigned SlotSize = 20>
void miosix::FixedEventQueue< NumSlots, SlotSize >::post ( Callback< SlotSize >  event)
inline

Post an event, blocking if the event queue is full.

Parameters
eventfunction function to be called in the thread that calls run() or runOne(). Bind can be used to bind parameters to the function. Unlike with the EventQueue, the operator= of the bound parameters have the restriction that they need to be callable from inside a InterruptDisableLock without causing undefined behaviour, so they must not, open files, print, ... but can allocate memory.
template<unsigned NumSlots, unsigned SlotSize = 20>
bool miosix::FixedEventQueue< NumSlots, SlotSize >::postNonBlocking ( Callback< SlotSize >  event)
inline

Post an event in the queue, or return if the queue was full.

Parameters
eventfunction function to be called in the thread that calls run() or runOne(). Bind can be used to bind parameters to the function. Unlike with the EventQueue, the operator= of the bound parameters have the restriction that they need to be callable from inside a InterruptDisableLock without causing undefined behaviour, so they must not open files, print, ... but can allocate memory.
Returns
false if there was no space in the queue
template<unsigned NumSlots, unsigned SlotSize = 20>
void miosix::FixedEventQueue< NumSlots, SlotSize >::run ( )
inline

This function blocks waiting for events being posted, and when available it calls the event function. To return from this event loop an event function must throw an exception.

Exceptions
anyexception that is thrown by the event functions
template<unsigned NumSlots, unsigned SlotSize = 20>
void miosix::FixedEventQueue< NumSlots, SlotSize >::runOne ( )
inline

Run at most one event. This function does not block.

Exceptions
anyexception that is thrown by the event functions
template<unsigned NumSlots, unsigned SlotSize = 20>
unsigned int miosix::FixedEventQueue< NumSlots, SlotSize >::size ( ) const
inline
Returns
the number of events in the queue

The documentation for this class was generated from the following file: