VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
makVrv::DtLockedBufferedQueue< T > Class Template Reference

template<typename T>
class makVrv::DtLockedBufferedQueue< T >

A locked buffered queue which allows multiple writers and a single reader. Internally the queue is stored as a double buffered vector. Ideally the vector will not shrink in size so frequent calls getForReading is advised.

Inheritance diagram for makVrv::DtLockedBufferedQueue< T >:
Inheritance graph
[legend]

Public Member Functions

 DtLockedBufferedQueue ()
 
 ~DtLockedBufferedQueue ()
 
unsigned int push (T value)
 
unsigned int push (std::vector< T > &valueVector)
 
void getForReading (std::vector< T > *&output)
 
void deleteAllPointers ()
 
void nullAllPointers ()
 
void clearBuffers ()
 

Protected Member Functions

void swapBuffers ()
 

Protected Attributes

std::vector< T > myFirstBuffer
 
std::vector< T > mySecondBuffer
 
std::vector< T > * myCurrentBuffer
 
DtMutex myBufferMutex
 

Constructor & Destructor Documentation

template<typename T>
makVrv::DtLockedBufferedQueue< T >::DtLockedBufferedQueue ( )
template<typename T>
makVrv::DtLockedBufferedQueue< T >::~DtLockedBufferedQueue ( )

DTOR If the type T is a pointer memory must be explicitly deleting by iterating throug both vectors call getForReading twice.

Member Function Documentation

template<typename T>
unsigned int makVrv::DtLockedBufferedQueue< T >::push ( value)

Add a value to to the buffer. This function is thread safe and reentrant. The return value is the current size of the buffer. This is useful when throttling writing speed due to insufficient reads.

template<typename T>
unsigned int makVrv::DtLockedBufferedQueue< T >::push ( std::vector< T > &  valueVector)

Add several values to to the buffer. This function is thread safe and reentrant. The return value is the current size of the buffer. This is useful when throttling writing speed due to insufficient reads.

template<typename T>
void makVrv::DtLockedBufferedQueue< T >::getForReading ( std::vector< T > *&  output)

Get a vector for reading. This function should only be called by the reader thread. The pointer reference is written to, and can be initially null. The pointer is guaranteed to be valid and not NULL after a call to getForReading. The pointer is only valid until the next call to getForReading. There is no need to clear the buffer when reading is done. The contents of the output will not change until the next call to getForReading. All iterators are invalidated with the next call to getForReading.

void printInt(int i) { std::cout << i << std::endl;}
...
std::vector<int>* readVector(0);
myQueue.getForReading(readVector);
//Print each integer,
std::for_each(readVector->begin(),readVector->end(),&printInt);
//Not necessary but not a bad idea either.
readVector = 0;
template<typename T>
void makVrv::DtLockedBufferedQueue< T >::deleteAllPointers ( )

Helper function for deleting all member pointers in both buffers. This function is not valid if T is not a pointer type, of the pointers are not allocated using 'new' or if they used new[].

Warning
This function is not thread safe.!!!!
template<typename T>
void makVrv::DtLockedBufferedQueue< T >::nullAllPointers ( )

Helper function for setting all member pointers to null in both buffers (for reference pointers, osg::ref_ptr). This function is not valid if T is not a pointer type, of the pointers are not allocated using 'new' or if they used new[].

Warning
This function is not thread safe.!!!!
template<typename T>
void makVrv::DtLockedBufferedQueue< T >::clearBuffers ( )

Helper function to clear all the buffers, if the buffers contain pointers call deleteAllPointers() first.

Warning
This function is not thread safe.!!!!
template<typename T>
void makVrv::DtLockedBufferedQueue< T >::swapBuffers ( )
protected

Internal function for swapping buffers and clearing the write buffer.

Member Data Documentation

template<typename T>
std::vector<T> makVrv::DtLockedBufferedQueue< T >::myFirstBuffer
protected
template<typename T>
std::vector<T> makVrv::DtLockedBufferedQueue< T >::mySecondBuffer
protected
template<typename T>
std::vector<T>* makVrv::DtLockedBufferedQueue< T >::myCurrentBuffer
protected
template<typename T>
DtMutex makVrv::DtLockedBufferedQueue< T >::myBufferMutex
protected

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

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)