Basic Image AlgorithmS Library
2.8.0
|
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... | |
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 !!!
Definition at line 60 of file FiFoQueue.hh.
|
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_.
|
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_.
|
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_.
|
inlineprotected |
Definition at line 266 of file FiFoQueue.hh.
|
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_.
|
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_.
|
inline |
Fetch the oldest item from the queue.
Again synced is blocking, thread will wait for an item if buffer is empty.
Definition at line 203 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_.
|
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_.
|
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_.
|
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_.
|
protected |
array holding cycled buffer
Definition at line 266 of file FiFoQueue.hh.
Referenced by BIAS::FiFoQueue< T >::AppendSynced(), BIAS::FiFoQueue< T >::AppendUnsynced(), BIAS::FiFoQueue< T >::FetchSynced(), BIAS::FiFoQueue< T >::FetchUnsynced(), BIAS::FiFoQueue< T >::FiFoQueue(), and BIAS::FiFoQueue< T >::~FiFoQueue().
|
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().
|
protected |
length of buffer (number of slots)
Definition at line 279 of file FiFoQueue.hh.
Referenced by BIAS::FiFoQueue< T >::AppendSynced(), BIAS::FiFoQueue< T >::AppendUnsynced(), BIAS::FiFoQueue< T >::FetchSynced(), BIAS::FiFoQueue< T >::FetchUnsynced(), BIAS::FiFoQueue< T >::FiFoQueue(), and BIAS::FiFoQueue< T >::GetBufferSize().
|
protected |
number of items in buffer
Definition at line 286 of file FiFoQueue.hh.
Referenced by BIAS::FiFoQueue< T >::AppendSynced(), BIAS::FiFoQueue< T >::AppendUnsynced(), BIAS::FiFoQueue< T >::FetchSynced(), BIAS::FiFoQueue< T >::FetchUnsynced(), and BIAS::FiFoQueue< T >::GetNumItems().
|
protected |
mutex for sync. locking (conditions and access)
Definition at line 276 of file FiFoQueue.hh.
Referenced by BIAS::FiFoQueue< T >::AppendSynced(), BIAS::FiFoQueue< T >::AppendUnsynced(), BIAS::FiFoQueue< T >::FetchSynced(), BIAS::FiFoQueue< T >::FetchUnsynced(), BIAS::FiFoQueue< T >::FiFoQueue(), BIAS::FiFoQueue< T >::GetNumItems(), and BIAS::FiFoQueue< T >::~FiFoQueue().
|
protected |
last (newest) element in queue
Definition at line 284 of file FiFoQueue.hh.
Referenced by BIAS::FiFoQueue< T >::AppendSynced(), BIAS::FiFoQueue< T >::AppendUnsynced(), BIAS::FiFoQueue< T >::FetchSynced(), and BIAS::FiFoQueue< T >::FetchUnsynced().
|
protected |
pthread condition variable for waiting for non empty buf
Definition at line 274 of file FiFoQueue.hh.
Referenced by BIAS::FiFoQueue< T >::AppendSynced(), BIAS::FiFoQueue< T >::AppendUnsynced(), BIAS::FiFoQueue< T >::FetchSynced(), BIAS::FiFoQueue< T >::FiFoQueue(), and BIAS::FiFoQueue< T >::~FiFoQueue().
|
protected |
pthread condition variable for waiting for non full buf
Definition at line 272 of file FiFoQueue.hh.
Referenced by BIAS::FiFoQueue< T >::AppendSynced(), BIAS::FiFoQueue< T >::FetchSynced(), BIAS::FiFoQueue< T >::FetchUnsynced(), BIAS::FiFoQueue< T >::FiFoQueue(), and BIAS::FiFoQueue< T >::~FiFoQueue().