If you can read this text, it means you are not experiencing this website at its best. This website is designed for used with a standards-compliant browser.
Current version: 2.3.2
ZThreads
A platform-independent, multi-threading and synchronization library for C++
Home Documentation Downloads CVS Contact
BoundedQueue< T, LockType, StorageType > Class Template Reference

#include <BoundedQueue.h>

Inheritance diagram for BoundedQueue< T, LockType, StorageType >:
Queue< T > Lockable Cancelable NonCopyable

Public Member Functions

 BoundedQueue (size_t capacity)
 
virtual ~BoundedQueue ()
 Destroy this Queue.
 
size_t capacity ()
 
virtual void add (const T &item)
 
virtual bool add (const 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)
 
virtual void acquire ()
 
virtual bool tryAcquire (unsigned long timeout)
 
virtual void release ()
 
- Public Member Functions inherited from Queue< T >
virtual ~Queue ()
 Destroy a Queue.
 
virtual void add (const T &item)=0
 
virtual bool add (const T &item, unsigned long timeout)=0
 
virtual T next ()=0
 
virtual T next (unsigned long timeout)=0
 
virtual void cancel ()=0
 
virtual size_t size ()=0
 
virtual size_t size (unsigned long timeout)=0
 
virtual bool empty ()
 
virtual bool empty (unsigned long timeout)
 
- Public Member Functions inherited from Cancelable
virtual ~Cancelable ()
 Destroy a Cancelable object.
 
virtual void cancel ()=0
 
virtual bool isCanceled ()=0
 
- Public Member Functions inherited from Lockable
virtual ~Lockable ()
 Destroy a Lockable object.
 
virtual void acquire ()=0
 
virtual bool tryAcquire (unsigned long timeout)=0
 
virtual void release ()=0
 

Detailed Description

template<class T, class LockType, typename StorageType = std::deque<T>>
class ZThread::BoundedQueue< T, LockType, StorageType >
Author
Eric Crahen http://www.code-foo.com
Date
<2003-07-16T13:54:04-0400>
Version
2.3.0

A BoundedQueue provides serialized access to a set of values. It differs from other Queues by adding a maximum capacity, giving it the following properties:

  • Threads calling the empty() methods will be blocked until the BoundedQueue becomes empty.
  • Threads calling the next() methods will be blocked until the BoundedQueue has a value to return.
  • Threads calling the add() methods will be blocked until the number of values in the Queue drops below the maximum capacity.
See also
Queue

Constructor & Destructor Documentation

◆ BoundedQueue()

BoundedQueue ( size_t  capacity)
inline

Create a BoundedQueue with the given capacity.

Parameters
capacitymaximum number of values to allow in the Queue at at any time

Member Function Documentation

◆ acquire()

virtual void acquire ( )
inlinevirtual

Acquire the Lockable object.

This method may or may not block the caller for an indefinite amount of time. Those details are defined by specializations of this class.

Exceptions
Interrupted_Exceptionthrown if the calling thread is interrupted before the operation completes.
Postcondition
The Lockable is acquired only if no exception was thrown.

Implements Lockable.

◆ add() [1/2]

virtual void add ( const T &  item)
inlinevirtual

Add a value to this Queue.

If the number of values in the queue matches the value returned by capacity() then the calling thread will be blocked until at least one value is removed from the Queue.

Parameters
itemvalue to be added to the Queue
Exceptions
Cancellation_Exceptionthrown if this Queue has been canceled.
Interrupted_Exceptionthrown if the thread was interrupted while waiting to add a value
Precondition
The Queue should not have been canceled prior to the invocation of this function.
Postcondition
If no exception is thrown, a copy of item will have been added to the Queue.
See also
Queue::add(const T& item)

Implements Queue< T >.

◆ add() [2/2]

virtual bool add ( const T &  item,
unsigned long  timeout 
)
inlinevirtual

Add a value to this Queue.

If the number of values in the queue matches the value returned by capacity() then the calling thread will be blocked until at least one value is removed from the Queue.

Parameters
itemvalue to be added to the Queue
timeoutmaximum amount of time (milliseconds) this method may block the calling thread.
Returns
  • true if a copy of item can be added before timeout milliseconds elapse.
  • false otherwise.
Exceptions
Cancellation_Exceptionthrown if this Queue has been canceled.
Interrupted_Exceptionthrown if the thread was interrupted while waiting to add a value
Precondition
The Queue should not have been canceled prior to the invocation of this function.
Postcondition
If no exception is thrown, a copy of item will have been added to the Queue.
See also
Queue::add(const T& item, unsigned long timeout)

Implements Queue< T >.

◆ cancel()

virtual void cancel ( )
inlinevirtual

Cancel this queue.

Postcondition
Any threads blocked by an add() function will throw a Cancellation_Exception.
Any threads blocked by a next() function will throw a Cancellation_Exception.
See also
Queue::cancel()

Implements Queue< T >.

◆ capacity()

size_t capacity ( )
inline

Get the maximum capacity of this Queue.

Returns
size_t maximum capacity

◆ empty() [1/2]

virtual bool empty ( )
inlinevirtual

Test whether any values are available in this Queue.

The calling thread is blocked until there are no values present in the Queue.

Returns
  • true if there are no values available.
  • false if there are values available.
See also
Queue::empty()

Reimplemented from Queue< T >.

◆ empty() [2/2]

virtual bool empty ( unsigned long  timeout)
inlinevirtual

Test whether any values are available in this Queue.

The calling thread is blocked until there are no values present in the Queue.

Parameters
timeoutmaximum amount of time (milliseconds) this method may block the calling thread.
Returns
  • true if there are no values available.
  • false if there are values available.
Exceptions
Timeout_Exceptionthrown if timeout milliseconds expire before a value becomes available
See also
Queue::empty()

Reimplemented from Queue< T >.

◆ isCanceled()

virtual bool isCanceled ( )
inlinevirtual
See also
Queue::isCanceled()

Implements Cancelable.

◆ next() [1/2]

virtual T next ( )
inlinevirtual

Retrieve and remove a value from this Queue.

If invoked when there are no values present to return then the calling thread will be blocked until a value arrives in the Queue.

Returns
T next available value
Exceptions
Cancellation_Exceptionthrown if this Queue has been canceled.
Interrupted_Exceptionthrown if the thread was interrupted while waiting to retrieve a value
Precondition
The Queue should not have been canceled prior to the invocation of this function.
Postcondition
The value returned will have been removed from the Queue.

Implements Queue< T >.

◆ next() [2/2]

virtual T next ( unsigned long  timeout)
inlinevirtual

Retrieve and remove a value from this Queue.

If invoked when there are no values present to return then the calling thread will be blocked until a value arrives in the Queue.

Parameters
timeoutmaximum amount of time (milliseconds) this method may block the calling thread.
Returns
T next available value
Exceptions
Cancellation_Exceptionthrown if this Queue has been canceled.
Timeout_Exceptionthrown if the timeout expires before a value can be retrieved.
Precondition
The Queue should not have been canceled prior to the invocation of this function.
Postcondition
The value returned will have been removed from the Queue.

Implements Queue< T >.

◆ release()

virtual void release ( )
inlinevirtual

Release the Lockable object.

This method may or may not block the caller for an indefinite amount of time. Those details are defined by specializations of this class.

Postcondition
The Lockable is released only if no exception was thrown.

Implements Lockable.

◆ size() [1/2]

virtual size_t size ( )
inlinevirtual
See also
Queue::size()

Implements Queue< T >.

◆ size() [2/2]

virtual size_t size ( unsigned long  timeout)
inlinevirtual

◆ tryAcquire()

virtual bool tryAcquire ( unsigned long  timeout)
inlinevirtual

Attempt to acquire the Lockable object.

This method may or may not block the caller for a definite amount of time. Those details are defined by specializations of this class; however, this method includes a timeout value that can be used to limit the maximum amount of time that a specialization could block.

Parameters
timeout- maximum amount of time (milliseconds) this method could block
Returns
  • true if the operation completes and the Lockable is acquired before the timeout expires.
  • false if the operation times out before the Lockable can be acquired.
Exceptions
Interrupted_Exceptionthrown if the calling thread is interrupted before the operation completes.
Postcondition
The Lockable is acquired only if no exception was thrown.

Implements Lockable.


The documentation for this class was generated from the following file: