RTT::internal::AtomicQueue< T > Class Template Reference

#include <AtomicQueue.hpp>

Inheritance diagram for RTT::internal::AtomicQueue< T >:
Inheritance graph
[legend]

List of all members.

Classes

union  SIndexes

Public Types

typedef unsigned int size_type
typedef unsigned int size_type

Public Member Functions

 AtomicQueue (unsigned int size)
 AtomicQueue (unsigned int size)
size_type capacity () const
size_type capacity () const
void clear ()
void clear ()
bool dequeue (T &result)
bool dequeue (T &result)
bool enqueue (const T &value)
bool enqueue (const T &value)
const T front () const
const T front () const
bool isEmpty () const
bool isEmpty () const
bool isFull () const
bool isFull () const
size_type size () const
size_type size () const
 ~AtomicQueue ()
 ~AtomicQueue ()

Private Types

typedef T C
typedef T C
typedef C *volatile CacheObjType
typedef C *volatile CacheObjType
typedef volatile CCachePtrType
typedef volatile CCachePtrType
typedef CPtrType
typedef CPtrType
typedef C ValueType
typedef C ValueType

Private Member Functions

 AtomicQueue (const AtomicQueue< T > &)
 AtomicQueue (const AtomicQueue< T > &)
CachePtrType propose_r ()
CachePtrType propose_r ()
CachePtrType propose_w ()
CachePtrType propose_w ()
CachePtrType recover_r () const
CachePtrType recover_r () const

Private Attributes

CachePtrType _buf
volatile SIndexes _indxes
const int _size

Detailed Description

template<class T>
class RTT::internal::AtomicQueue< T >

Create an atomic, non-blocking single ended queue (FIFO) for storing a pointer to T. It is a Many Readers, Many Writers implementation based on the atomic Compare And Swap instruction. Any number of threads may access the queue concurrently.

This queue tries to obey strict ordering, but under high contention of reads interfering writes, one or more elements may be dequeued out of order. For this reason, size() is expensive to accurately calculate the size.

Due to the same limitations, it is possible that the full capacity of the queue is not used (simulations show seldomly an off by one element if capacity==10) and that isFull() returns true, while size() < capacity().

Warning:
You can not store null pointers.
Parameters:
T The pointer type to be stored in the Queue. Example : AtomicQueue< A* > is a queue of pointers to A.

Definition at line 70 of file install/include/rtt/internal/AtomicQueue.hpp.


Member Typedef Documentation

template<class T>
typedef T RTT::internal::AtomicQueue< T >::C [private]

Definition at line 73 of file rtt/internal/AtomicQueue.hpp.

template<class T>
typedef T RTT::internal::AtomicQueue< T >::C [private]

Definition at line 73 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
typedef C* volatile RTT::internal::AtomicQueue< T >::CacheObjType [private]

Definition at line 75 of file rtt/internal/AtomicQueue.hpp.

template<class T>
typedef C* volatile RTT::internal::AtomicQueue< T >::CacheObjType [private]

Definition at line 75 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
typedef volatile C* RTT::internal::AtomicQueue< T >::CachePtrType [private]

Definition at line 74 of file rtt/internal/AtomicQueue.hpp.

template<class T>
typedef volatile C* RTT::internal::AtomicQueue< T >::CachePtrType [private]

Definition at line 74 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
typedef C* RTT::internal::AtomicQueue< T >::PtrType [private]

Definition at line 77 of file rtt/internal/AtomicQueue.hpp.

template<class T>
typedef C* RTT::internal::AtomicQueue< T >::PtrType [private]

Definition at line 77 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
typedef unsigned int RTT::internal::AtomicQueue< T >::size_type

Definition at line 184 of file rtt/internal/AtomicQueue.hpp.

template<class T>
typedef unsigned int RTT::internal::AtomicQueue< T >::size_type
template<class T>
typedef C RTT::internal::AtomicQueue< T >::ValueType [private]

Definition at line 76 of file rtt/internal/AtomicQueue.hpp.

template<class T>
typedef C RTT::internal::AtomicQueue< T >::ValueType [private]

Definition at line 76 of file install/include/rtt/internal/AtomicQueue.hpp.


Constructor & Destructor Documentation

template<class T>
RTT::internal::AtomicQueue< T >::AtomicQueue ( const AtomicQueue< T > &   )  [private]
template<class T>
RTT::internal::AtomicQueue< T >::AtomicQueue ( unsigned int  size  )  [inline]

Create an AtomicQueue with queue size size.

Parameters:
size The size of the queue, should be 1 or greater.

Definition at line 190 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
RTT::internal::AtomicQueue< T >::~AtomicQueue (  )  [inline]
template<class T>
RTT::internal::AtomicQueue< T >::AtomicQueue ( const AtomicQueue< T > &   )  [private]
template<class T>
RTT::internal::AtomicQueue< T >::AtomicQueue ( unsigned int  size  )  [inline]

Create an AtomicQueue with queue size size.

Parameters:
size The size of the queue, should be 1 or greater.

Definition at line 190 of file rtt/internal/AtomicQueue.hpp.

template<class T>
RTT::internal::AtomicQueue< T >::~AtomicQueue (  )  [inline]

Definition at line 197 of file rtt/internal/AtomicQueue.hpp.


Member Function Documentation

template<class T>
size_type RTT::internal::AtomicQueue< T >::capacity (  )  const [inline]

Return the maximum number of items this queue can contain.

Definition at line 231 of file rtt/internal/AtomicQueue.hpp.

template<class T>
size_type RTT::internal::AtomicQueue< T >::capacity (  )  const [inline]

Return the maximum number of items this queue can contain.

Definition at line 231 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
void RTT::internal::AtomicQueue< T >::clear (  )  [inline]

Clear all contents of the Queue and thus make it empty.

Definition at line 304 of file rtt/internal/AtomicQueue.hpp.

template<class T>
void RTT::internal::AtomicQueue< T >::clear (  )  [inline]

Clear all contents of the Queue and thus make it empty.

Definition at line 304 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
bool RTT::internal::AtomicQueue< T >::dequeue ( T &  result  )  [inline]

Dequeue an item.

Parameters:
value The value dequeued.
Returns:
false if queue is empty, true if dequeued.

Definition at line 278 of file rtt/internal/AtomicQueue.hpp.

template<class T>
bool RTT::internal::AtomicQueue< T >::dequeue ( T &  result  )  [inline]

Dequeue an item.

Parameters:
value The value dequeued.
Returns:
false if queue is empty, true if dequeued.

Definition at line 278 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
bool RTT::internal::AtomicQueue< T >::enqueue ( const T &  value  )  [inline]

Enqueue an item.

Parameters:
value The value to enqueue, not zero.
Returns:
false if queue is full or value is zero, true if queued.

Definition at line 258 of file rtt/internal/AtomicQueue.hpp.

template<class T>
bool RTT::internal::AtomicQueue< T >::enqueue ( const T &  value  )  [inline]

Enqueue an item.

Parameters:
value The value to enqueue, not zero.
Returns:
false if queue is full or value is zero, true if queued.

Definition at line 258 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
const T RTT::internal::AtomicQueue< T >::front (  )  const [inline]

Return the next to be read value.

Definition at line 296 of file rtt/internal/AtomicQueue.hpp.

template<class T>
const T RTT::internal::AtomicQueue< T >::front (  )  const [inline]

Return the next to be read value.

Definition at line 296 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
bool RTT::internal::AtomicQueue< T >::isEmpty (  )  const [inline]

Inspect if the Queue is empty.

Returns:
true if empty, false otherwise.

Definition at line 220 of file rtt/internal/AtomicQueue.hpp.

template<class T>
bool RTT::internal::AtomicQueue< T >::isEmpty (  )  const [inline]

Inspect if the Queue is empty.

Returns:
true if empty, false otherwise.

Definition at line 220 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
bool RTT::internal::AtomicQueue< T >::isFull (  )  const [inline]

Inspect if the Queue is full.

Returns:
true if full, false otherwise.

Definition at line 206 of file rtt/internal/AtomicQueue.hpp.

template<class T>
bool RTT::internal::AtomicQueue< T >::isFull (  )  const [inline]

Inspect if the Queue is full.

Returns:
true if full, false otherwise.

Definition at line 206 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
CachePtrType RTT::internal::AtomicQueue< T >::propose_r (  )  [inline, private]

Atomic advance and wrap of the Read pointer. Return the data position or zero if queue is empty.

Definition at line 157 of file rtt/internal/AtomicQueue.hpp.

template<class T>
CachePtrType RTT::internal::AtomicQueue< T >::propose_r (  )  [inline, private]

Atomic advance and wrap of the Read pointer. Return the data position or zero if queue is empty.

Definition at line 157 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
CachePtrType RTT::internal::AtomicQueue< T >::propose_w (  )  [inline, private]

Atomic advance and wrap of the Write pointer. Return the old position or zero if queue is full.

Definition at line 131 of file rtt/internal/AtomicQueue.hpp.

template<class T>
CachePtrType RTT::internal::AtomicQueue< T >::propose_w (  )  [inline, private]

Atomic advance and wrap of the Write pointer. Return the old position or zero if queue is full.

Definition at line 131 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
CachePtrType RTT::internal::AtomicQueue< T >::recover_r (  )  const [inline, private]

The loose ordering may cause missed items in our queue which are not pointed at by the read pointer. This function recovers such items from _buf.

Returns:
zero if nothing to recover, the location of a lost item otherwise.

Definition at line 104 of file rtt/internal/AtomicQueue.hpp.

template<class T>
CachePtrType RTT::internal::AtomicQueue< T >::recover_r (  )  const [inline, private]

The loose ordering may cause missed items in our queue which are not pointed at by the read pointer. This function recovers such items from _buf.

Returns:
zero if nothing to recover, the location of a lost item otherwise.

Definition at line 104 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
size_type RTT::internal::AtomicQueue< T >::size (  )  const [inline]

Return the exact number of elements in the queue. This is slow because it scans the whole queue.

Definition at line 241 of file rtt/internal/AtomicQueue.hpp.

template<class T>
size_type RTT::internal::AtomicQueue< T >::size (  )  const [inline]

Return the exact number of elements in the queue. This is slow because it scans the whole queue.

Definition at line 241 of file install/include/rtt/internal/AtomicQueue.hpp.


Member Data Documentation

template<class T>
CachePtrType RTT::internal::AtomicQueue< T >::_buf [private]

The pointer to the buffer can be cached, the contents are volatile.

Definition at line 89 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
volatile SIndexes RTT::internal::AtomicQueue< T >::_indxes [private]

The indexes are packed into one double word. Therefore the read and write index can be read and written atomically.

Definition at line 95 of file install/include/rtt/internal/AtomicQueue.hpp.

template<class T>
const int RTT::internal::AtomicQueue< T >::_size [private]

Definition at line 72 of file install/include/rtt/internal/AtomicQueue.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


rtt
Author(s): RTT Developers
autogenerated on Fri Jan 11 09:49:57 2013