Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BIAS::FiFoQueue< T > Class Template Reference

This class implements a templated standard FiFo-queue for inter process communication (arbitrary number of readers/writers), e.g. More...

#include <Base/Common/FiFoQueue.hh>

Public Member Functions

int AppendSynced (T &item)
 Append an datum as newest item. More...
 
int AppendUnsynced (T &item)
 Append an datum as newest item. More...
 
int FetchSynced (T &item)
 Fetch the oldest item from the queue. More...
 
int FetchUnsynced (T &item)
 Fetch the oldest item from the queue. More...
 
 FiFoQueue ()
 Default constructor. More...
 
 FiFoQueue (unsigned length)
 Constructor. More...
 
unsigned GetBufferSize ()
 Returns the size of underlying ringbuffer -> maximum number of items in queue. More...
 
unsigned GetNumItems ()
 Return the number of items in queue. More...
 
 ~FiFoQueue ()
 Just a cleanup. More...
 

Protected Member Functions

 FiFoQueue (FiFoQueue &data)
 

Protected Attributes

T * data_
 array holding cycled buffer More...
 
unsigned head_
 first (oldest) element in queue More...
 
const unsigned length_
 length of buffer (number of slots) More...
 
unsigned numItems_
 number of items in buffer More...
 
pthread_mutex_t * syncMutex_
 mutex for sync. locking (conditions and access) More...
 
unsigned tail_
 last (newest) element in queue More...
 
pthread_cond_t * triggerCondEmpty_
 pthread condition variable for waiting for non empty buf More...
 
pthread_cond_t * triggerCondFull_
 pthread condition variable for waiting for non full buf More...
 

Detailed Description

template<class T>
class BIAS::FiFoQueue< T >

This class implements a templated standard FiFo-queue for inter process communication (arbitrary number of readers/writers), e.g.

    between GUIs and underlying processes. It can be used as synced or
    unsynced.
    FiFo: Oldest item will be return at first. Items once fetched are
    'deleted' from the queue.
    synced:   process is block until a free slot available for writing
              -> AppendSynced
              or an item is available for read
              -> FetchSynced
    unsynced: no item is returned from empty buffer when reading and
              oldest item gets 'lost' when buffer is full during
              writing
    !!! ATTENTION: WHEN TEMPLATED OVER POINTERS DATA 'BEHIND' !!!
    !!! THE POINTER WON'T DELETED WHEN BUFFER IS FULL DURING  !!!
    !!! WRITING                                               !!!
Author
BIAS

Definition at line 60 of file FiFoQueue.hh.

Constructor & Destructor Documentation

template<class T>
BIAS::FiFoQueue< T >::FiFoQueue ( )
inline

Default constructor.

Creates a queue with defined default size BIAS_FIFOQUEUE_DEFAULT_SIZE and initializes mutex-/condition- variables

Definition at line 67 of file FiFoQueue.hh.

References BIAS::FiFoQueue< T >::data_, BIAS::FiFoQueue< T >::syncMutex_, BIAS::FiFoQueue< T >::triggerCondEmpty_, and BIAS::FiFoQueue< T >::triggerCondFull_.

template<class T>
BIAS::FiFoQueue< T >::FiFoQueue ( unsigned  length)
inline

Constructor.

Creates a queue with given size and initializes mutex-/condition-variables

Definition at line 84 of file FiFoQueue.hh.

References BIAS::FiFoQueue< T >::data_, BIAS::FiFoQueue< T >::length_, BIAS::FiFoQueue< T >::syncMutex_, BIAS::FiFoQueue< T >::triggerCondEmpty_, and BIAS::FiFoQueue< T >::triggerCondFull_.

template<class T>
BIAS::FiFoQueue< T >::~FiFoQueue ( )
inline

Just a cleanup.

!!! ATTENTION: WHEN USING POINTERS AS TEMPLATE TYPE ONLY THE !!! !!! BUFFER IS DELETED - NOT THE DATA 'BEHIND' THE POINTERS !!!

Definition at line 102 of file FiFoQueue.hh.

References BIAS::FiFoQueue< T >::data_, BIAS::FiFoQueue< T >::syncMutex_, BIAS::FiFoQueue< T >::triggerCondEmpty_, and BIAS::FiFoQueue< T >::triggerCondFull_.

template<class T>
BIAS::FiFoQueue< T >::FiFoQueue ( FiFoQueue< T > &  data)
inlineprotected

Definition at line 266 of file FiFoQueue.hh.

Member Function Documentation

template<class T>
int BIAS::FiFoQueue< T >::AppendSynced ( T &  item)
inline

Append an datum as newest item.

Syncron in the sens of blocking, that is, threads inserting an item to a full queue are delayed until a slot is available (item has been fetched)

Definition at line 136 of file FiFoQueue.hh.

References BIAS::FiFoQueue< T >::data_, BIAS::FiFoQueue< T >::head_, BIAS::FiFoQueue< T >::length_, BIAS::FiFoQueue< T >::numItems_, BIAS::FiFoQueue< T >::syncMutex_, BIAS::FiFoQueue< T >::tail_, BIAS::FiFoQueue< T >::triggerCondEmpty_, and BIAS::FiFoQueue< T >::triggerCondFull_.

template<class T>
int BIAS::FiFoQueue< T >::AppendUnsynced ( T &  item)
inline

Append an datum as newest item.

Asyncron in the sens of non-blocking, that is, threads inserting an item to a full queue will overwrite the oldest item. This gets 'lost'. !!! ATTENTION: OVERWRITING A POINTER TYPE DOES NO FREE MEMORY !!!

Definition at line 169 of file FiFoQueue.hh.

References BIAS::FiFoQueue< T >::data_, BIAS::FiFoQueue< T >::head_, BIAS::FiFoQueue< T >::length_, BIAS::FiFoQueue< T >::numItems_, BIAS::FiFoQueue< T >::syncMutex_, BIAS::FiFoQueue< T >::tail_, and BIAS::FiFoQueue< T >::triggerCondEmpty_.

template<class T>
int BIAS::FiFoQueue< T >::FetchSynced ( T &  item)
inline
template<class T>
int BIAS::FiFoQueue< T >::FetchUnsynced ( T &  item)
inline

Fetch the oldest item from the queue.

Again unsynced is non-blocking, thread won't wait for an item if buffer is empty. In this case the input-/ output-param is left unchanged and 1 is returned.

Definition at line 235 of file FiFoQueue.hh.

References BIAS::FiFoQueue< T >::data_, BIAS::FiFoQueue< T >::length_, BIAS::FiFoQueue< T >::numItems_, BIAS::FiFoQueue< T >::syncMutex_, BIAS::FiFoQueue< T >::tail_, and BIAS::FiFoQueue< T >::triggerCondFull_.

template<class T>
unsigned BIAS::FiFoQueue< T >::GetBufferSize ( )
inline

Returns the size of underlying ringbuffer -> maximum number of items in queue.

Definition at line 128 of file FiFoQueue.hh.

References BIAS::FiFoQueue< T >::length_.

template<class T>
unsigned BIAS::FiFoQueue< T >::GetNumItems ( )
inline

Return the number of items in queue.

Definition at line 117 of file FiFoQueue.hh.

References BIAS::FiFoQueue< T >::numItems_, and BIAS::FiFoQueue< T >::syncMutex_.

Member Data Documentation

template<class T>
T* BIAS::FiFoQueue< T >::data_
protected
template<class T>
unsigned BIAS::FiFoQueue< T >::head_
protected

first (oldest) element in queue

Definition at line 282 of file FiFoQueue.hh.

Referenced by BIAS::FiFoQueue< T >::AppendSynced(), BIAS::FiFoQueue< T >::AppendUnsynced(), and BIAS::FiFoQueue< T >::FetchSynced().

template<class T>
const unsigned BIAS::FiFoQueue< T >::length_
protected
template<class T>
unsigned BIAS::FiFoQueue< T >::numItems_
protected
template<class T>
pthread_mutex_t* BIAS::FiFoQueue< T >::syncMutex_
protected
template<class T>
unsigned BIAS::FiFoQueue< T >::tail_
protected
template<class T>
pthread_cond_t* BIAS::FiFoQueue< T >::triggerCondEmpty_
protected
template<class T>
pthread_cond_t* BIAS::FiFoQueue< T >::triggerCondFull_
protected

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