Main Page   Namespace List   Class Hierarchy   Compound List   Compound Members  

ZThread::BufferedQueue Class Template Reference

#include <BufferedQueue.h>

Inheritance diagram for ZThread::BufferedQueue::

ZThread::Queue ZThread::Cancelable List of all members.

Public Methods

 BufferedQueue (unsigned int capacity)
virtual ~BufferedQueue () throw ()
unsigned int capacity ()
virtual void add (T item) throw (Synchronization_Exception)
virtual T next () throw (Synchronization_Exception)
virtual T next (unsigned long timeout) throw (Synchronization_Exception)
virtual void cancel () throw (Synchronization_Exception)
virtual bool isCanceled () throw (Synchronization_Exception)
virtual bool empty () throw (Synchronization_Exception)

Protected Attributes

LOCK _lock
 Serialize access.

Condition _notFull
 Signaled if not full.

Condition _notEmpty
 Signaled if not empty.

Condition _isEmpty
 Signaled if empty.

std::deque<T> _queue
 Backing deque.

bool _canceled
 Cancellation flag.


Detailed Description

template<class T, class LOCK = Mutex> class ZThread::BufferedQueue

Date:
04-12-2001
Author:
Eric Crahen
Version:
1.3.4

BufferedQueue's are the most heavyweight queue included in this package. This queue will block threads adding too many items, withdrawing items from it in th empty state, and threads waiting for the queue to become empty.


Constructor & Destructor Documentation

BufferedQueue ( unsigned int capacity ) [inline]
 

Create a new queue with the given capacity. This capacity can not be altered once the queue is created

Parameters:
int   capacity
Parameters:
capacity  

~BufferedQueue ( ) throw () [inline, virtual]
 

Destroy this Queue


Member Function Documentation

void add ( T item ) throw (Synchronization_Exception) [inline, virtual]
 

Insert a new item into the queue.

The calling thread will be blocked if the queue has reached its capacity. Execution of that thread will continue after items are removed and the queue is not filled to capacity any longer.

One thread blocked by a next() request will be woken up.

This implementation signals a condition variable used to block threads waiting for items to be added to the queue

Parameters:
T   o - item to add
Exceptions:
InterruptedException  
CancelationException   - the queue has been canceled.

Precondition:
Objects add()ed should not be 'null'.
Parameters:
item  

Reimplemented from ZThread::Queue.

void cancel ( ) throw (Synchronization_Exception) [inline, virtual]
 

Cancel this queue, no more additions will be accepted.

Postcondition:
- next() will no longer block when he queue is empty it will return 'null'. Thread waiting to add will wake and throw CancelationException
Exceptions:
InterruptedException  

Reimplemented from ZThread::Queue.

unsigned int capacity ( ) [inline]
 

Get the capacity of this queue.

Returns:
unsigned int capacity

bool empty ( ) throw (Synchronization_Exception) [inline, virtual]
 

Test the queue to determine if it has been emptied. The calling thread is blocked until the queue empties

A Queue can reach empty many times during its lifetime it is not a one time occurrence. However, after a queue has been canceled it will reach empty only once more

Exceptions:
InterruptedException  

Reimplemented from ZThread::Queue.

bool isCanceled ( ) throw (Synchronization_Exception) [inline, virtual]
 

Check the cancelation status of this Queue

Returns:
bool - Queue cancled

Reimplemented from ZThread::Cancelable.

T next ( unsigned long timeout ) throw (Synchronization_Exception) [inline, virtual]
 

Take an item from the queue, block if empty. If the given time expires

Parameters:
unsigned   long - max time

Returns:
T - next available object
Exceptions:
InterruptedException  
CancelationException   - the queue has been canceled.
Timeout_Exception   - thrown if the given amount of time has expired and the queue could not return an item
Parameters:
timeout  

Reimplemented from ZThread::Queue.

T next ( ) throw (Synchronization_Exception) [inline, virtual]
 

Take an item from the queue, block if empty. If the given time expires

Returns:
T - next available object
Exceptions:
InterruptedException  
CancelationException   - the queue has been canceled.

Reimplemented from ZThread::Queue.


The documentation for this class was generated from the following file:
Generated at Fri Aug 31 09:07:59 2001 for ZThread by doxygen1.2.8 written by Dimitri van Heesch, © 1997-2001