Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
RTT::internal::AtomicMWMRQueue< T > Class Template Reference

#include <AtomicMWMRQueue.hpp>

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

Classes

union  SIndexes
 

Public Types

typedef AtomicQueue< T >::size_type size_type
 
- Public Types inherited from RTT::internal::AtomicQueue< T >
typedef unsigned int size_type
 

Public Member Functions

 AtomicMWMRQueue (unsigned int size)
 
size_type capacity () const
 
void clear ()
 
bool dequeue (T &result)
 
bool enqueue (const T &value)
 
const T front () const
 
bool isEmpty () const
 
bool isFull () const
 
size_type size () const
 
 ~AtomicMWMRQueue ()
 
- Public Member Functions inherited from RTT::internal::AtomicQueue< T >
virtual ~AtomicQueue ()
 

Private Types

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

Private Member Functions

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

Private Attributes

CachePtrType _buf
 
volatile SIndexes _indxes
 
const int _size
 

Detailed Description

template<class T>
class RTT::internal::AtomicMWMRQueue< 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
TThe pointer type to be stored in the Queue. Example : AtomicQueue< A* > is a queue of pointers to A.

Definition at line 71 of file AtomicMWMRQueue.hpp.

Member Typedef Documentation

template<class T >
typedef T RTT::internal::AtomicMWMRQueue< T >::C
private

Definition at line 74 of file AtomicMWMRQueue.hpp.

template<class T >
typedef C* volatile RTT::internal::AtomicMWMRQueue< T >::CacheObjType
private

Definition at line 76 of file AtomicMWMRQueue.hpp.

template<class T >
typedef volatile C* RTT::internal::AtomicMWMRQueue< T >::CachePtrType
private

Definition at line 75 of file AtomicMWMRQueue.hpp.

template<class T >
typedef C* RTT::internal::AtomicMWMRQueue< T >::PtrType
private

Definition at line 78 of file AtomicMWMRQueue.hpp.

template<class T >
typedef AtomicQueue<T>::size_type RTT::internal::AtomicMWMRQueue< T >::size_type

Definition at line 185 of file AtomicMWMRQueue.hpp.

template<class T >
typedef C RTT::internal::AtomicMWMRQueue< T >::ValueType
private

Definition at line 77 of file AtomicMWMRQueue.hpp.

Constructor & Destructor Documentation

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

Create an AtomicQueue with queue size size.

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

Definition at line 191 of file AtomicMWMRQueue.hpp.

template<class T >
RTT::internal::AtomicMWMRQueue< T >::~AtomicMWMRQueue ( )
inline

Definition at line 198 of file AtomicMWMRQueue.hpp.

Member Function Documentation

template<class T >
size_type RTT::internal::AtomicMWMRQueue< T >::capacity ( ) const
inlinevirtual

Return the maximum number of items this queue can contain.

Implements RTT::internal::AtomicQueue< T >.

Definition at line 232 of file AtomicMWMRQueue.hpp.

template<class T >
void RTT::internal::AtomicMWMRQueue< T >::clear ( )
inlinevirtual

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

Implements RTT::internal::AtomicQueue< T >.

Definition at line 305 of file AtomicMWMRQueue.hpp.

template<class T >
bool RTT::internal::AtomicMWMRQueue< T >::dequeue ( T &  result)
inlinevirtual

Dequeue an item.

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

Implements RTT::internal::AtomicQueue< T >.

Definition at line 279 of file AtomicMWMRQueue.hpp.

template<class T >
bool RTT::internal::AtomicMWMRQueue< T >::enqueue ( const T &  value)
inlinevirtual

Enqueue an item.

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

Implements RTT::internal::AtomicQueue< T >.

Definition at line 259 of file AtomicMWMRQueue.hpp.

template<class T >
const T RTT::internal::AtomicMWMRQueue< T >::front ( ) const
inlinevirtual

Return the next to be read value.

Implements RTT::internal::AtomicQueue< T >.

Definition at line 297 of file AtomicMWMRQueue.hpp.

template<class T >
bool RTT::internal::AtomicMWMRQueue< T >::isEmpty ( ) const
inlinevirtual

Inspect if the Queue is empty.

Returns
true if empty, false otherwise.

Implements RTT::internal::AtomicQueue< T >.

Definition at line 221 of file AtomicMWMRQueue.hpp.

template<class T >
bool RTT::internal::AtomicMWMRQueue< T >::isFull ( ) const
inlinevirtual

Inspect if the Queue is full.

Returns
true if full, false otherwise.

Implements RTT::internal::AtomicQueue< T >.

Definition at line 207 of file AtomicMWMRQueue.hpp.

template<class T >
CachePtrType RTT::internal::AtomicMWMRQueue< T >::propose_r ( )
inlineprivate

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

Definition at line 158 of file AtomicMWMRQueue.hpp.

template<class T >
CachePtrType RTT::internal::AtomicMWMRQueue< T >::propose_w ( )
inlineprivate

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

Definition at line 132 of file AtomicMWMRQueue.hpp.

template<class T >
CachePtrType RTT::internal::AtomicMWMRQueue< T >::recover_r ( ) const
inlineprivate

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 105 of file AtomicMWMRQueue.hpp.

template<class T >
size_type RTT::internal::AtomicMWMRQueue< T >::size ( ) const
inlinevirtual

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

Implements RTT::internal::AtomicQueue< T >.

Definition at line 242 of file AtomicMWMRQueue.hpp.

Member Data Documentation

template<class T >
CachePtrType RTT::internal::AtomicMWMRQueue< T >::_buf
private

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

Definition at line 90 of file AtomicMWMRQueue.hpp.

template<class T >
volatile SIndexes RTT::internal::AtomicMWMRQueue< 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 96 of file AtomicMWMRQueue.hpp.

template<class T >
const int RTT::internal::AtomicMWMRQueue< T >::_size
private

Definition at line 73 of file AtomicMWMRQueue.hpp.


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


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:46