The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
mha_rt_fifo_t< T > Class Template Reference

Template class for thread safe, half real time safe fifo without explixit locks. More...

Public Member Functions

 mha_rt_fifo_t ()
 Construct empty fifo. More...
 
 ~mha_rt_fifo_t ()
 Destructor will delete all data currently in the fifo. More...
 
T * poll ()
 Retrieve the latest element in the Fifo. More...
 
T * poll_1 ()
 Retrieve the next element in the Fifo, if there is one, and mark the previous element as abandonned. More...
 
void push (T *data)
 Add element to the Fifo. More...
 

Private Member Functions

void remove_abandonned ()
 Deletes abandonned elements. More...
 
void remove_all ()
 Deletes all elements. More...
 

Private Attributes

mha_rt_fifo_element_t< T > * root
 The first element in the fifo. Deleting elements starts here. More...
 
mha_rt_fifo_element_t< T > * current
 The element most recently returned by poll or poll_1. More...
 

Detailed Description

template<class T>
class mha_rt_fifo_t< T >

Template class for thread safe, half real time safe fifo without explixit locks.

Reading from this fifo is realtime safe, writing to it is not. This fifo is designed for objects that were constructed on the heap. It assumes ownership of these objects and calls delete on them when they are no longer used. Objects remain inside the Fifo while being used by the reader.

A new fifo element is inserted by using push. The push operation is not real time safe, it allocates and deallocates memory. The latest element is retrieved by calling poll. This operation will skip fifo elements if more than one push has been occured since the last poll. To avoid skipping, call the poll_1 operation instead.

Constructor & Destructor Documentation

◆ mha_rt_fifo_t()

template<class T >
mha_rt_fifo_t< T >::mha_rt_fifo_t ( )
inline

Construct empty fifo.

◆ ~mha_rt_fifo_t()

template<class T >
mha_rt_fifo_t< T >::~mha_rt_fifo_t ( )
inline

Destructor will delete all data currently in the fifo.

Member Function Documentation

◆ poll()

template<class T >
T* mha_rt_fifo_t< T >::poll ( )
inline

Retrieve the latest element in the Fifo.

Will skip fifo elements if more than one element has been added since last poll invocation. Will return the same element as on last call if no elements have been added in the mean time. Marks former elements as abandonned.

Returns
The latest element in this Fifo. Returns NULL if the Fifo is empty.

◆ poll_1()

template<class T >
T* mha_rt_fifo_t< T >::poll_1 ( )
inline

Retrieve the next element in the Fifo, if there is one, and mark the previous element as abandonned.

Else, if there is no newer element, returns the same element as on last poll() or poll_1() invocation.

Returns
The next element in this Fifo, if there is one, or the same as before. Returns NULL if the Fifo is empty.

◆ push()

template<class T >
void mha_rt_fifo_t< T >::push ( T *  data)
inline

Add element to the Fifo.

Deletes abandonned elements in the fifo.

Parameters
dataThe new user data to place at the end of the fifo. After this invocation, the fifo is the owner of this object and will delete it when it is no longer used. data must have been allocated on the heap with standard operator new.

◆ remove_abandonned()

template<class T >
void mha_rt_fifo_t< T >::remove_abandonned ( )
inlineprivate

Deletes abandonned elements.

◆ remove_all()

template<class T >
void mha_rt_fifo_t< T >::remove_all ( )
inlineprivate

Deletes all elements.

Member Data Documentation

◆ root

template<class T >
mha_rt_fifo_element_t<T>* mha_rt_fifo_t< T >::root
private

The first element in the fifo. Deleting elements starts here.

◆ current

template<class T >
mha_rt_fifo_element_t<T>* mha_rt_fifo_t< T >::current
private

The element most recently returned by poll or poll_1.

Searching for new elements starts here.


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