Main Page   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members  

BoundedQueue Class Template Reference

#include <BoundedQueue.h>

Inheritance diagram for BoundedQueue:

Queue Cancelable NonCopyable List of all members.

Public Methods

 BoundedQueue (unsigned int capacity)
virtual ~BoundedQueue () throw ()
 Destroy this Queueand any remaining items.

unsigned int capacity ()
virtual void add (T item)
virtual void add (T item, unsigned long timeout)
virtual T next ()
virtual T next (unsigned long timeout)
virtual void cancel ()
virtual bool isCanceled ()
virtual size_t size ()
virtual size_t size (unsigned long timeout)
virtual bool empty ()
virtual bool empty (unsigned long timeout)

Detailed Description

template<class T, class LockType, typename StorageType = std::deque<T>>
class ZThread::BoundedQueue< T, LockType, StorageType >

Author:
Eric Crahen <crahen@cse.buffalo.edu>
Date:
<2002-07-15T10:01:28-0400>
Version:
2.2.0
A BoundedQueues is a Queue implementation that provides serialized access to the items added to it. It addition, a BoundedQueues will block threads calling empty() methods until the Queue becomes empty. Similarly, threads calling the next() methods will be blocked until items arrive. Finally, threads calling the the add() methods will be blocked if the Queue is at capacity.


Constructor & Destructor Documentation

BoundedQueue 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


Member Function Documentation

virtual void add   item,
unsigned long    timeout
[inline, virtual]
 

Add an object to this Queue, tranfering the ownership of that object to the Queue. As the new owner, the Queue becomes responsible for deleting the add()ed object.

This method may block the caller for an indefinite amount of time if the Queue is at capacity.

Parameters:
item  - object to attempt to add to this Queue
timeout  - maximum amount of time (milliseconds) this method could block
Returns :
true if the item was add()ed before the given timeout expired. Otherwise false
See also:
Queue::add(T, unsigned long)
Postcondition:
if the Queue was empty, threads blocked by a next() method will be awakend if no exception is thrown

Implements Queue.

virtual void add   item [inline, virtual]
 

Add an object to this Queue, tranfering the ownership of that object to the Queue. As the new owner, the Queue becomes responsible for deleting the add()ed object.

This method may block the caller for an indefinite amount of time if the Queue is at capacity.

Parameters:
item  - object to attempt to add to this Queue
See also:
Queue::add(T)
Postcondition:
if the Queue was empty, threads blocked by a next() method will be awakend if no exception is thrown

Implements Queue.

virtual void cancel   [inline, virtual]
 

Cancel this queue.

This method will block the calling thread until exclusive access to the Queue can be obtained or until an exception is thrown.

See also:
Queue::cancel()
Postcondition:
If threads are blocked on a next(), empty() or size() method, they will awakend

Implements Queue.

unsigned int capacity   [inline]
 

Get the capacity of this Queue. When the Queue is at capacity the add() methods will block.

Returns :
unsigned int capacity

virtual bool empty unsigned long    timeout [inline, virtual]
 

Test this Queue to see if it is empty. This will block the calling thread until the Queue becomes empty.

Parameters:
timeout  - maximum amount of time (millseconds) this method could block
Returns :
boolean true if empty, otherwise false
Exceptions:
Cancellation_Exception  should not be thrown. A cancel()ed Queue that contains no more elements should report that it is empty.
Interrupted_Exception  thrown if the the method is invoked from the context of a thread that has been interrupt()ed.
Timeout_Exception  thrown if the given amount of time has expired before an item becomes available
Synchronization_Exception  thrown if there is some error in counting the items.
See also:
Queue::empty(unsigned long)

Reimplemented from Queue.

virtual bool empty   [inline, virtual]
 

Test this Queue to see if it is empty. This will block the calling thread until the Queue becomes empty.

Returns :
boolean true if empty, otherwise false
Exceptions:
Cancellation_Exception  should not be thrown. A cancel()ed Queue that contains no more elements should report that it is empty.
Interrupted_Exception  thrown if the the method is invoked from the context of a thread that has been interrupt()ed.
Timeout_Exception  thrown if the given amount of time has expired before an item becomes available
Synchronization_Exception  thrown if there is some error in counting the items.
See also:
Queue::empty()

Reimplemented from Queue.

virtual bool isCanceled   [inline, virtual]
 

Determine if this Queue has been cancel()ed.

This method will block the calling thread until exclusive access to the Queue can be obtained or until an exception is thrown.

Returns :
bool true if cancel() was called prior to this method, otherwise false.
See also:
Queue::isCanceled()

Implements Cancelable.

virtual T next unsigned long    timeout [inline, virtual]
 

Get an object from this Queue.

This method will block the calling thread until an item arrives in the Queue or until an exception is thrown.

Parameters:
timeout  - maximum amount of time (milliseconds) this method could block
Returns :
T next available object
See also:
Queue::next(unsigned long)
Exceptions:
Cancellation_Exception  thrown if there are no items available in the Queue and the Queue has become cancel()ed
Postcondition:
if the Queue becomes empty as a result of this method, threads blocked by an empty() method will be awakend.

Implements Queue.

virtual T next   [inline, virtual]
 

Get an object from this Queue.

This method will block the calling thread until an item arrives in the Queue or until an exception is thrown.

Returns :
T next available object
See also:
Queue::next()
Exceptions:
Cancellation_Exception  thrown if there are no items available in the Queue and the Queue has become cancel()ed
Postcondition:
if the Queue becomes empty as a result of this method, threads blocked by an empty() or size() method will be awakend.

Implements Queue.

virtual size_t size unsigned long    timeout [inline, virtual]
 

Count the items present in this Queue.

This method will not block the calling thread.

Parameters:
timeout  - maximum amount of time (millseconds) this method could block
Returns :
size_t number of elements available in the Queue. These are retrievable through the next() methods.
See also:
Queue::size(unsigned long)

Implements Queue.

virtual size_t size   [inline, virtual]
 

Count the items present in this Queue.

This method will not block the calling thread.

Returns :
size_t number of elements available in the Queue. These are retrievable through the next() methods.
See also:
Queue::size()

Implements Queue.


The documentation for this class was generated from the following file:
Generated on Tue Aug 27 07:43:10 2002 for ZThread by doxygen1.2.17