libcommonc++  0.7
BoundedQueue< T > Class Template Reference

A bounded, threadsafe FIFO processing queue. More...

#include <BoundedQueue.h++>

Public Member Functions

 BoundedQueue (uint_t capacity)
 Construct a new BoundedQueue. More...
 
virtual ~BoundedQueue ()
 Destructor. More...
 
void clear ()
 Clear the queue. More...
 
void reset ()
 Reset the queue. More...
 
void put (T item)
 Put an item in the queue. More...
 
void tryPut (T item, timespan_ms_t timeout=0)
 Put an item in the queue. More...
 
take ()
 Take an item from the queue. More...
 
tryTake (timespan_ms_t timeout=0)
 Take an item from the queue. More...
 
uint_t getSize () const
 Get the size of the queue, that is, the number of items currently in the queue. More...
 
uint_t getCapacity () const
 Get the capacity of the queue, that is, the maximum number of items that the queue can hold. More...
 
void setCapacity (uint_t capacity)
 Change the capacity of the queue. More...
 
void interrupt ()
 Interrupt the queue. More...
 
void shutdown ()
 Shut down the queue. More...
 
bool isShutdown () const
 Test if the queue has been shut down. More...
 

Detailed Description

template<typename T>
class ccxx::BoundedQueue< T >

A bounded, threadsafe FIFO processing queue.

Items are enqueued by one or more producers and consumed by one or more consumers.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ BoundedQueue()

BoundedQueue ( uint_t  capacity)

Construct a new BoundedQueue.

Parameters
capacityThe queue capacity: the maximum number of items that it can hold at any given time.

◆ ~BoundedQueue()

virtual ~BoundedQueue ( )
virtual

Destructor.

Member Function Documentation

◆ clear()

void clear ( )

Clear the queue.

All items are removed from the queue.

◆ getCapacity()

uint_t getCapacity ( ) const
inline

Get the capacity of the queue, that is, the maximum number of items that the queue can hold.

◆ getSize()

uint_t getSize ( ) const

Get the size of the queue, that is, the number of items currently in the queue.

◆ interrupt()

void interrupt ( )

Interrupt the queue.

Unblocks any pending operations, causing the corresponding methods to throw an InterruptedException.

◆ isShutdown()

bool isShutdown ( ) const
inline

Test if the queue has been shut down.

◆ put()

void put ( item)

Put an item in the queue.

If the queue is full, the method blocks until space becomes available.

Parameters
itemThe item to enqueue.
Exceptions
InterruptedExceptionIf the queue was interrupted via a call to interrupt().

◆ reset()

void reset ( )

Reset the queue.

Clears the queue, and clears the shutdown flag, if it was previously set via a call to shutdown(). This method must be called before a shut down queue can be reused.

◆ setCapacity()

void setCapacity ( uint_t  capacity)

Change the capacity of the queue.

Parameters
capacityThe new capacity. If the value is less than 1, the request is ignored. It is possible to set the capacity to be less than the number of elements currently in the queue; in this case it will not be possible to add more elements until the size of the queue drops below the new capacity.

◆ shutdown()

void shutdown ( )

Shut down the queue.

All subsequent operations will throw an InterruptedException.

◆ take()

T take ( )

Take an item from the queue.

If the queue is empty, the method blocks until an item becomes available.

Returns
The dequeued item.
Exceptions
InterruptedExceptionIf the queue was interrupted via a call to interrupt().

◆ tryPut()

void tryPut ( item,
timespan_ms_t  timeout = 0 
)

Put an item in the queue.

If the queue is full, the method blocks until space becomes available or the timeout expires, whichever occurs first.

Parameters
itemThe item to enqueue.
timeoutThe timeout, in milliseconds.
Exceptions
InterruptedExceptionIf the queue was interrupted via a call to interrupt().
TimeoutExceptionIf the operation timed out.

◆ tryTake()

T tryTake ( timespan_ms_t  timeout = 0)

Take an item from the queue.

If the queue is empty, the method blocks until an item becomes available or the timeout expires, whichever occurs first.

Parameters
timeoutThe timeout, in milliseconds.
Returns
The dequeued item.
Exceptions
InterruptedExceptionIf the queue was interrupted via a call to interrupt().
TimeoutExceptionIf the operation timed out.

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