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

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

Waitable template LIFO structure. More...

#include <wefts_stack.h>

Collaboration diagram for Wefts::Stack< T >:

Collaboration graph
[legend]
List of all members.

Public Methods

 Stack (unsigned int maxLen=0)
 Creates a stack.

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

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


Protected Attributes

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

Private Methods

void p_waitForFree ()
void p_waitForFull ()

Detailed Description

template<class T>
class Wefts::Stack< T >

Waitable template LIFO structure.

A Stack, in Wefts++ context, is an Last-in first-out synchronization object, where one or more thread are posting data, and one or more thread are waiting for data to become available to process it. The last data posted will be retreived by the first thread coming in search for data.

Stack 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.

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

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

Note:
It is illegal to destroy a Stack while there are threads waiting.


Constructor & Destructor Documentation

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

Creates a stack.

If the parameter is zero, the stack 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 stack or 0.


Member Function Documentation

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

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

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

Pops data from the stack.

Stacks are LIFO, that is Last in, First out. The last 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 stack 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:
an  element that will receive the popped value.
wait  if false, returns immediately if the stack is empty.
Returns:
true if operation suceeded, false if stack is full and wait parameter is false

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

Pushes data in the stack.

Stacks are LIFO, that is Last in, First out. The last element you push will be served first to the waiters.

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


Member Data Documentation

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

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

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


The documentation for this class was generated from the following file:
Generated on Mon Dec 22 04:12:40 2003 for Wefts by doxygen1.2.18