libcommonc++
0.7
|
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... | |
T | take () |
Take an item from the queue. More... | |
T | 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... | |
A bounded, threadsafe FIFO processing queue.
Items are enqueued by one or more producers and consumed by one or more consumers.
BoundedQueue | ( | uint_t | capacity | ) |
Construct a new BoundedQueue.
capacity | The queue capacity: the maximum number of items that it can hold at any given time. |
|
virtual |
Destructor.
void clear | ( | ) |
Clear the queue.
All items are removed from the queue.
|
inline |
Get the capacity of the queue, that is, the maximum number of items that the queue can hold.
uint_t getSize | ( | ) | const |
Get the size of the queue, that is, the number of items currently in the queue.
void interrupt | ( | ) |
Interrupt the queue.
Unblocks any pending operations, causing the corresponding methods to throw an InterruptedException.
|
inline |
Test if the queue has been shut down.
void put | ( | T | item | ) |
Put an item in the queue.
If the queue is full, the method blocks until space becomes available.
item | The item to enqueue. |
InterruptedException | If the queue was interrupted via a call to interrupt(). |
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.
void setCapacity | ( | uint_t | capacity | ) |
Change the capacity of the queue.
capacity | The 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. |
void shutdown | ( | ) |
Shut down the queue.
All subsequent operations will throw an InterruptedException.
T take | ( | ) |
Take an item from the queue.
If the queue is empty, the method blocks until an item becomes available.
InterruptedException | If the queue was interrupted via a call to interrupt(). |
void tryPut | ( | T | 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.
item | The item to enqueue. |
timeout | The timeout, in milliseconds. |
InterruptedException | If the queue was interrupted via a call to interrupt(). |
TimeoutException | If the operation timed out. |
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.
timeout | The timeout, in milliseconds. |
InterruptedException | If the queue was interrupted via a call to interrupt(). |
TimeoutException | If the operation timed out. |