cxxtools::Queue< T > Class Template Reference

This class implements a thread safe queue. More...

#include <cxxtools/queue.h>

Public Types

typedef T value_type
typedef std::deque< T >::size_type size_type
typedef std::deque< T >
::const_reference 
const_reference

Public Member Functions

 Queue ()
 Default Constructor.
value_type get ()
 Returns the next element.
std::pair< value_type, bool > get (const Milliseconds &timeout)
 Returns the next element if the queue is not empty.
std::pair< value_type, bool > tryGet ()
 Returns the next element if the queue is not empty.
void put (const_reference element, bool force=false)
 Adds a element to the queue.
bool remove (const_reference element)
 Removes one specific element.
bool empty () const
 Returns true, if the queue is empty.
bool waitEmpty (Milliseconds timeout=-1) const
 Waits until timeout or queue empty.
size_type size () const
 Returns the number of elements currently in queue.
void maxSize (size_type m)
 sets the maximum size of the queue.
size_type maxSize () const
 returns the maximum size of the queue.
size_type numWaiting () const
 returns the number of threads blocked in the get method.

Detailed Description

template<typename T>
class cxxtools::Queue< T >

This class implements a thread safe queue.

A queue is a container where the elements put into the queue are fetched in the same order (first-in-first-out, fifo). The class has a optional maximum size. If the size is set to 0 the queue has no limit. Otherwise putting a element to the queue may block until another thread fetches a element or increases the limit.

Member Typedef Documentation

template<typename T>
typedef std::deque<T>::const_reference cxxtools::Queue< T >::const_reference
template<typename T>
typedef std::deque<T>::size_type cxxtools::Queue< T >::size_type
template<typename T>
typedef T cxxtools::Queue< T >::value_type

Constructor & Destructor Documentation

template<typename T>
cxxtools::Queue< T >::Queue ( )
inline

Default Constructor.

Member Function Documentation

template<typename T>
bool cxxtools::Queue< T >::empty ( ) const
inline

Returns true, if the queue is empty.

template<typename T >
Queue< T >::value_type cxxtools::Queue< T >::get ( )

Returns the next element.

This method returns the next element. If the queue is empty, the thread will be locked until a element is available.

template<typename T >
std::pair< typename Queue< T >::value_type, bool > cxxtools::Queue< T >::get ( const Milliseconds timeout)

Returns the next element if the queue is not empty.

This method returns the next element. If the queue is empty, the thread will wait up to timeout milliseconds until a element is available.

If the queue was empty after the timeout, a pair of a default constructed value_type and the value false are returned. Otherwise the next element is removed and returned together with a true value.

Spurious wakeups are ignored so that when that happens, the method might return before the timeout is over even when the queue is empty.

template<typename T >
void cxxtools::Queue< T >::maxSize ( size_type  m)

sets the maximum size of the queue.

Setting the maximum size of the queue may wake up another thread, if it is waiting for space to get available and the limit is increased.

template<typename T>
size_type cxxtools::Queue< T >::maxSize ( ) const
inline

returns the maximum size of the queue.

template<typename T>
size_type cxxtools::Queue< T >::numWaiting ( ) const
inline

returns the number of threads blocked in the get method.

template<typename T>
void cxxtools::Queue< T >::put ( const_reference  element,
bool  force = false 
)

Adds a element to the queue.

This method adds a element to the queue. If the queue has reached his maximum size, the method blocks until there is space available.

template<typename T >
bool cxxtools::Queue< T >::remove ( const_reference  element)

Removes one specific element.

This method removes one specific element from the queue. It returns true, when the element was found and removed.

template<typename T>
size_type cxxtools::Queue< T >::size ( ) const
inline

Returns the number of elements currently in queue.

template<typename T >
std::pair< typename Queue< T >::value_type, bool > cxxtools::Queue< T >::tryGet ( )

Returns the next element if the queue is not empty.

If the queue is empty, a default constructed value_type is returned. The returned flag is set to false, if the queue was empty.

template<typename T>
bool cxxtools::Queue< T >::waitEmpty ( Milliseconds  timeout = -1) const
inline

Waits until timeout or queue empty.

Waits until timeout or queue empty. Returns true when queue is not empty.


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