Orocos Real-Time Toolkit  2.6.0
Public Types | Public Member Functions
RTT::internal::AtomicQueue< T > Class Template Reference

Create an atomic, non-blocking single ended queue (FIFO) for storing a pointer to T. More...

#include <rtt/internal/AtomicQueue.hpp>

Inheritance diagram for RTT::internal::AtomicQueue< T >:
RTT::internal::Queue< T >

List of all members.

Public Types

typedef unsigned int size_type

Public Member Functions

 AtomicQueue (unsigned int size)
 Create an AtomicQueue with queue size size.
bool isFull () const
 Inspect if the Queue is full.
bool isEmpty () const
 Inspect if the Queue is empty.
size_type capacity () const
 Return the maximum number of items this queue can contain.
size_type size () const
 Return the exact number of elements in the queue.
bool enqueue (const T &value)
 Enqueue an item.
bool dequeue (T &result)
 Dequeue an item.
const T front () const
 Return the next to be read value.
void clear ()
 Clear all contents of the Queue and thus make it empty.

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

Definition at line 70 of file AtomicQueue.hpp.


Constructor & Destructor Documentation

template<class T >
RTT::internal::AtomicQueue< T >::AtomicQueue ( 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 190 of file AtomicQueue.hpp.

References RTT::internal::AtomicQueue< T >::clear().


Member Function Documentation

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

Dequeue an item.

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

Definition at line 278 of file AtomicQueue.hpp.

References RTT::os::CAS().

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

Enqueue an item.

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

Definition at line 258 of file AtomicQueue.hpp.

References RTT::os::CAS().

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 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 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 AtomicQueue.hpp.


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