forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
forest::Quu< T > Class Template Reference

This class implements a simple thread-safe queue for communication among threads. More...

#include <Quu.h>

Collaboration diagram for forest::Quu< T >:

Public Member Functions

 Quu (int=10)
 Constructor for Quu objects. More...
 
 ~Quu ()
 Destructor for Quu objects. More...
 
void reset ()
 Reset the queue, discarding any contents. More...
 
void resize (int)
 Resize the queue, discarding any contents. More...
 
bool empty () const
 Determine if queue is empty. More...
 
void enq (T)
 Add value to the end of the queue. More...
 
deq ()
 Remove and return first item in the queue. More...
 

Private Attributes

int qMax
 max number of items in queue
 
int count
 number of items in queue
 
int head
 index of first item in buf
 
int tail
 index of first empty space in buf
 
T * buf
 where values are stored
 
mutex mtx
 used to ensure mutual exclusion
 
condition_variable emptyQ
 condition variable for empty queue
 
condition_variable fullQ
 condition variable for full queue
 

Detailed Description

template<class T>
class forest::Quu< T >

This class implements a simple thread-safe queue for communication among threads.

Definition at line 28 of file Quu.h.

Constructor & Destructor Documentation

template<class T >
forest::Quu< T >::Quu ( int  qMax1 = 10)

Constructor for Quu objects.

Parameters
qMax1is the maximum number of elements that can be queued.

Definition at line 56 of file Quu.h.

template<class T >
forest::Quu< T >::~Quu ( )

Destructor for Quu objects.

Definition at line 64 of file Quu.h.

Member Function Documentation

template<class T >
T forest::Quu< T >::deq ( )

Remove and return first item in the queue.

The calling thread is blocked if the queue is empty.

Returns
the next item in the queue

Definition at line 113 of file Quu.h.

Here is the caller graph for this function:

template<class T >
bool forest::Quu< T >::empty ( ) const
inline

Determine if queue is empty.

Returns
true if the queue is empty, else false

Definition at line 90 of file Quu.h.

Here is the caller graph for this function:

template<class T>
void forest::Quu< T >::enq ( x)

Add value to the end of the queue.

The calling thread is blocked if the queue is full.

Parameters
iis the value to be added.

Definition at line 97 of file Quu.h.

Here is the caller graph for this function:

template<class T >
void forest::Quu< T >::reset ( )
inline

Reset the queue, discarding any contents.

This should only be used in contexts where there is a single writer, and only the writing thread should do it.

Definition at line 71 of file Quu.h.

template<class T >
void forest::Quu< T >::resize ( int  nuSiz)
inline

Resize the queue, discarding any contents.

This should only be used when the queue is empty and preferably before any threads are using the Quu.

Definition at line 81 of file Quu.h.


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