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

A Lock-free buffer implementation to read and write data of type T in a FIFO way. More...

#include <rtt/base/BufferLockFree.hpp>

Inheritance diagram for RTT::base::BufferLockFree< T >:
RTT::base::BufferInterface< T > RTT::base::BufferBase RTT::base::Buffer< T >

List of all members.

Public Types

typedef BufferInterface< T >
::reference_t 
reference_t
typedef BufferInterface< T >
::param_t 
param_t
typedef BufferInterface< T >
::size_type 
size_type
typedef T value_t
typedef boost::shared_ptr
< BufferInterface< T > > 
shared_ptr

Public Member Functions

 BufferLockFree (unsigned int bufsize, const T &initial_value=T(), bool circular=false)
 Create a lock-free buffer wich can store bufsize elements.
virtual void data_sample (const T &sample)
 Initializes this buffer with a data sample, such that for dynamical allocated types T, the buffer can reserve place to hold these elements.
virtual T data_sample () const
 Reads back a data sample.
size_type capacity () const
 Returns the maximum number of items that can be stored in the buffer.
size_type size () const
 Returns the actual number of items that are stored in the buffer.
bool empty () const
 Check if this buffer is empty.
bool full () const
 Check if this buffer is full.
void clear ()
 Clears all contents of this buffer.
bool Push (param_t item)
 Write a single value to the buffer.
size_type Push (const std::vector< T > &items)
 Write a sequence of values to the buffer.
bool Pop (reference_t item)
 Read the oldest value from the buffer.
size_type Pop (std::vector< T > &items)
 Read the whole buffer.
value_t * PopWithoutRelease ()
 Returns a pointer to the first element in the buffer.
void Release (value_t *item)
 Releases the pointer.

Detailed Description

template<class T>
class RTT::base::BufferLockFree< T >

A Lock-free buffer implementation to read and write data of type T in a FIFO way.

No memory allocation is done during read or write. One thread may read and any number of threads may write this buffer.

Parameters:
TThe value type to be stored in the Buffer. Example : BufferLockFree is a buffer which holds values of type A.

Definition at line 68 of file BufferLockFree.hpp.


Constructor & Destructor Documentation

template<class T >
RTT::base::BufferLockFree< T >::BufferLockFree ( unsigned int  bufsize,
const T &  initial_value = T(),
bool  circular = false 
) [inline]

Create a lock-free buffer wich can store bufsize elements.

Parameters:
bufsizethe capacity of the buffer. '

Definition at line 87 of file BufferLockFree.hpp.

References RTT::internal::TsPool< T >::data_sample().


Member Function Documentation

template<class T >
size_type RTT::base::BufferLockFree< T >::capacity ( ) const [inline, virtual]

Returns the maximum number of items that can be stored in the buffer.

Returns:
maximum number of items.

Implements RTT::base::BufferBase.

Definition at line 115 of file BufferLockFree.hpp.

References RTT::internal::AtomicMWSRQueue< T >::capacity().

Referenced by RTT::base::BufferLockFree< T >::Push().

template<class T >
void RTT::base::BufferLockFree< T >::clear ( ) [inline, virtual]

Clears all contents of this buffer.

Implements RTT::base::BufferBase.

Definition at line 135 of file BufferLockFree.hpp.

References RTT::internal::AtomicMWSRQueue< T >::dequeue().

template<class T >
virtual void RTT::base::BufferLockFree< T >::data_sample ( const T &  sample) [inline, virtual]

Initializes this buffer with a data sample, such that for dynamical allocated types T, the buffer can reserve place to hold these elements.

Postcondition:
Calling this function causes all data in the buffer to be lost and the size being reset to zero.

Implements RTT::base::BufferInterface< T >.

Definition at line 98 of file BufferLockFree.hpp.

References RTT::internal::TsPool< T >::data_sample().

template<class T >
bool RTT::base::BufferLockFree< T >::empty ( ) const [inline, virtual]

Check if this buffer is empty.

Returns:
true if size() == 0

Implements RTT::base::BufferBase.

Definition at line 125 of file BufferLockFree.hpp.

References RTT::internal::AtomicMWSRQueue< T >::isEmpty().

template<class T >
bool RTT::base::BufferLockFree< T >::full ( ) const [inline, virtual]

Check if this buffer is full.

Returns:
true if size() == capacity()

Implements RTT::base::BufferBase.

Definition at line 130 of file BufferLockFree.hpp.

References RTT::internal::AtomicMWSRQueue< T >::isFull().

template<class T >
bool RTT::base::BufferLockFree< T >::Pop ( reference_t  item) [inline, virtual]

Read the oldest value from the buffer.

Parameters:
itemis to be set with a value from the buffer.
Returns:
true if something was read.

Implements RTT::base::BufferInterface< T >.

Definition at line 194 of file BufferLockFree.hpp.

References RTT::internal::AtomicMWSRQueue< T >::dequeue().

template<class T >
size_type RTT::base::BufferLockFree< T >::Pop ( std::vector< T > &  items) [inline, virtual]

Read the whole buffer.

Parameters:
itemsis to be filled with all values in the buffer, with items.begin() the oldest value.
Returns:
the number of items read.

Implements RTT::base::BufferInterface< T >.

Definition at line 205 of file BufferLockFree.hpp.

References RTT::internal::AtomicMWSRQueue< T >::dequeue().

template<class T >
value_t* RTT::base::BufferLockFree< T >::PopWithoutRelease ( ) [inline, virtual]

Returns a pointer to the first element in the buffer.

The pointer is only garanteed to stay valid until the next pop operation.

Note the pointer needs the be released by calling Release on the buffer.

Returns:
a pointer to a sample or Zero if buffer is empty

Implements RTT::base::BufferInterface< T >.

Definition at line 217 of file BufferLockFree.hpp.

References RTT::internal::AtomicMWSRQueue< T >::dequeue().

template<class T >
bool RTT::base::BufferLockFree< T >::Push ( param_t  item) [inline, virtual]

Write a single value to the buffer.

Parameters:
itemthe value to write
Returns:
false if the buffer is full.

Implements RTT::base::BufferInterface< T >.

Definition at line 142 of file BufferLockFree.hpp.

References RTT::base::BufferLockFree< T >::capacity(), RTT::internal::AtomicMWSRQueue< T >::dequeue(), RTT::internal::AtomicMWSRQueue< T >::enqueue(), and RTT::internal::AtomicMWSRQueue< T >::size().

Referenced by RTT::base::BufferLockFree< T >::Push().

template<class T >
size_type RTT::base::BufferLockFree< T >::Push ( const std::vector< T > &  items) [inline, virtual]

Write a sequence of values to the buffer.

Parameters:
itemsthe values to write
Returns:
the number of values written (may be less than items.size())

Implements RTT::base::BufferInterface< T >.

Definition at line 181 of file BufferLockFree.hpp.

References RTT::base::BufferLockFree< T >::Push().

template<class T >
void RTT::base::BufferLockFree< T >::Release ( value_t *  item) [inline, virtual]

Releases the pointer.

Parameters:
itempointer aquired using PopWithoutRelease()

Implements RTT::base::BufferInterface< T >.

Definition at line 225 of file BufferLockFree.hpp.

template<class T >
size_type RTT::base::BufferLockFree< T >::size ( ) const [inline, virtual]

Returns the actual number of items that are stored in the buffer.

Returns:
number of items.

Implements RTT::base::BufferBase.

Definition at line 120 of file BufferLockFree.hpp.

References RTT::internal::AtomicMWSRQueue< T >::size().


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