Main Page   Namespace List   Class Hierarchy   Compound List   Compound Members  

ZThread::MonitoredQueue Class Template Reference

#include <MonitoredQueue.h>

Inheritance diagram for ZThread::MonitoredQueue::

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

Public Methods

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

Protected Attributes

LOCK _lock
 Serialize access.

Condition _notEmpty
 Signaled on not empty.

Condition _isEmpty
 Signaled on empty.

std::deque<T> _queue
 Backing deque.

bool _canceled
 Cancellation flag.


Detailed Description

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

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


Constructor & Destructor Documentation

MonitoredQueue ( ) throw () [inline]
 

Create a new Queue

~MonitoredQueue ( ) 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. 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
Exceptions:
InterruptedException  

Reimplemented from ZThread::Queue.

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

Block calling until the queue becomes empty. This implementation should always return true.

This implementation waits on a condition variable that is broadcast to each time the queue removed its last element. This can be a periodic occurrence; you may have a faster consumer than producer, for example. In this case, the queue might be emptied several times before it is canceled.

Returns:
boolean true if empty, false if not.
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.

Any threads blocked by an empty call are awoken if this call empties the queue. The queue will try to acquire the lock it owns for up to timeout milliseconds, it will throw a timeout only when that time has expired w/o obtaining a lock

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 calling thread if empty.

Any threads blocked by an empty call are awoken if this call empties the queue

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

Reimplemented from ZThread::Queue.


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