Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Wefts::Queue< T > Class Template Reference
[Advanced Syncronization constructs]

Waitable template FIFO structure. More...

#include <wefts_queue.h>

Collaboration diagram for Wefts::Queue< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Queue (unsigned int maxLen=0)
 Creates a queue.

bool push (T elem, const bool wait=false)
 Pushes data in the queue.

bool pop (T &elem, const bool wait=true)
 Pops data from the queue.


Protected Attributes

FastCondition m_cond
unsigned long m_maxLen
std::list< T > m_list

Private Member Functions

void p_waitForFree ()
void p_waitForFull ()

Detailed Description

template<class T>
class Wefts::Queue< T >

Waitable template FIFO structure.

A Queue, in Wefts++ context, is an object where one or more thread are posting data, and one or more thread are waiting for data to become available to process it.

Queue is a fast and clean way to pass arbitrary data in a 1:1 scheme from a producer to a consumer (or from a master to a worker) even if there are more producer/masters and consumer/workers running at the same time.

Queues have not any scheduling poicies; the first thread that is able to wake up will take the first element available.

By default, queues have infinite lenght. You can set a maximum lenght and in that case, a thread willing to post a new data will be blocked until the queue becomes free again, or will immediately return an error (depending on user preferences).

Note:
It is illegal to destroy a Queue while there are threads waiting. Class SmartQueue has a mechanism to prevent this problem, but this is somewhat more expensive in terms of speed.


Constructor & Destructor Documentation

template<class T>
Wefts::Queue< T >::Queue unsigned int  maxLen = 0  )  [inline]
 

Creates a queue.

If the parameter is zero, the queue will have infinite lenght; if it is not zero, push() method will block or return immediately false when the maximum lenght is reached.

Parameters:
maxLen maximum lenght of the queue or 0.


Member Function Documentation

template<class T>
void Wefts::Queue< T >::p_waitForFree  )  [inline, private]
 

template<class T>
void Wefts::Queue< T >::p_waitForFull  )  [inline, private]
 

template<class T>
bool Wefts::Queue< T >::pop T &  elem,
const bool  wait = true
[inline]
 

Pops data from the queue.

Queues are FIFO, that is First in, First out. The first element you push will be served first to the waiters.

Note that the default behavior of pop() is to wait until there is some data to be placed in the parameter, but you can also set wait parameter to false to have an immediate return in case of the queue being empty in that moment.

A blocking pop() is a cancelation point; be sure you have a proper cleanup scheme set up before to call a blocking pop.

Parameters:
elem an element that will receive the popped value.
wait if false, returns immediately if the queue is empty.
Returns:
true if operation suceeded, false if queue is full and wait parameter is false

template<class T>
bool Wefts::Queue< T >::push elem,
const bool  wait = false
[inline]
 

Pushes data in the queue.

Queues are FIFO, that is First in, First out. The first element you push will be served first to the waiters.

Parameters:
elem the data to be pushed in the Queue
wait true to wait in case the queue is full, false to return immediately
Returns:
true if operation suceeded, false if queue is full and wait parameter is false


Member Data Documentation

template<class T>
FastCondition Wefts::Queue< T >::m_cond [protected]
 

template<class T>
std::list<T> Wefts::Queue< T >::m_list [protected]
 

template<class T>
unsigned long Wefts::Queue< T >::m_maxLen [protected]
 


The documentation for this class was generated from the following file:
Generated on Sat Mar 13 21:05:44 2004 for Wefts by doxygen 1.3.5