RTT::BufferLockFree< T, ReadPolicy, WritePolicy > Class Template Reference
[Data Transfer Ports]

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

#include <rtt/BufferLockFree.hpp>

Inheritance diagram for RTT::BufferLockFree< T, ReadPolicy, WritePolicy >:
RTT::BufferInterface< T > RTT::ReadInterface< T > RTT::WriteInterface< T > RTT::BufferBase RTT::BufferBase RTT::Buffer< T, ReadPolicy, WritePolicy >

List of all members.

Public Types

typedef ReadInterface< T >
::reference_t 
reference_t
typedef WriteInterface< 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())
 Create a lock-free buffer wich can store bufsize elements.
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 write (param_t d)
 Write a single value to the buffer.
bool Push (param_t item)
size_type write (const std::vector< T > &d)
 Write a sequence of values to the buffer.
size_type Push (const std::vector< T > &items)
 Write a sequence of values to the buffer.
bool read (T &res)
 Read the oldest value from the buffer.
value_t front () const
 Get the next value to be Pop()'ed, or the default value if empty.
bool Pop (reference_t item)
size_type read (std::vector< T > &res)
 Read the whole buffer.
size_type Pop (std::vector< T > &items)
 Read the whole buffer.
virtual bool Pop (reference_t item)=0
 Read the oldest value from the buffer.
virtual bool Push (param_t item)=0
 Write a single value to the buffer.

Detailed Description

template<class T, class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
class RTT::BufferLockFree< T, ReadPolicy, WritePolicy >

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

Optionally block (synchronize) on an empty of full buffer (See Policy below ). The default Policy is thus completely Asynchronous (non-blocking). No memory allocation is done during read or write, any number of threads may access this buffer concurrently.

Parameters:
T The value type to be stored in the Buffer. Example : BufferLockFree is a buffer which holds values of type A.
ReadPolicy The Policy to block (wait) on empty (during read), using BlockingPolicy, or to return false, using NonBlockingPolicy (Default). This does not influence partial filled buffer behaviour.
WritePolicy The Policy to block (wait) on full (during write), using BlockingPolicy, or to return false, using NonBlockingPolicy (Default). This does not influence partial filled buffer behaviour.

Definition at line 76 of file BufferLockFree.hpp.


Constructor & Destructor Documentation

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::BufferLockFree ( unsigned int  bufsize,
const T &  initial_value = T() 
) [inline]

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

Parameters:
bufsize the capacity of the buffer. '

Definition at line 94 of file BufferLockFree.hpp.


Member Function Documentation

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
size_type RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::capacity (  )  const [inline, virtual]

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

Returns:
maximum number of items.

Implements RTT::BufferBase.

Definition at line 99 of file BufferLockFree.hpp.

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
bool RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::empty (  )  const [inline, virtual]

Check if this buffer is empty.

Returns:
true if size() == 0

Implements RTT::BufferBase.

Definition at line 109 of file BufferLockFree.hpp.

References RTT::AtomicQueue< T, ReadPolicy, WritePolicy >::isEmpty().

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
bool RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::full (  )  const [inline, virtual]

Check if this buffer is full.

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

Implements RTT::BufferBase.

Definition at line 114 of file BufferLockFree.hpp.

References RTT::AtomicQueue< T, ReadPolicy, WritePolicy >::isFull().

template<class T>
virtual bool RTT::ReadInterface< T >::Pop ( reference_t  item  )  [pure virtual, inherited]

Read the oldest value from the buffer.

Parameters:
item is to be set with a value from the buffer.
Returns:
true if something was read.
template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
size_type RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::Pop ( std::vector< T > &  items  )  [inline, virtual]

Read the whole buffer.

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

Implements RTT::ReadInterface< T >.

Definition at line 220 of file BufferLockFree.hpp.

References RTT::FixedSizeMemoryPool< T >::deallocate(), and RTT::AtomicQueue< T, ReadPolicy, WritePolicy >::dequeue().

template<class T>
virtual bool RTT::WriteInterface< T >::Push ( param_t  item  )  [pure virtual, inherited]

Write a single value to the buffer.

Parameters:
item the value to write
Returns:
false if the buffer is full.
template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
size_type RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::Push ( const std::vector< T > &  items  )  [inline, virtual]

Write a sequence of values to the buffer.

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

Implements RTT::WriteInterface< T >.

Definition at line 162 of file BufferLockFree.hpp.

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
size_type RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::read ( std::vector< T > &  res  )  [inline]

Read the whole buffer.

Block if empty if Policy is BlockingPolicy.

Parameters:
res is to be filled with all values in the buffer, with res.begin() the oldest value.
Returns:
the number of items read.
Deprecated:
by Pop( std::vector<T>& items )

Definition at line 215 of file BufferLockFree.hpp.

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
bool RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::read ( T &  res  )  [inline]

Read the oldest value from the buffer.

Block if empty if Policy is BlockingPolicy.

Parameters:
res is to be filled with a value from the buffer.
Returns:
true if something was read.
Deprecated:
by Pop( reference_t item )

Definition at line 180 of file BufferLockFree.hpp.

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
size_type RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::size (  )  const [inline, virtual]

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

Returns:
number of items.

Implements RTT::BufferBase.

Definition at line 104 of file BufferLockFree.hpp.

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
size_type RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::write ( const std::vector< T > &  d  )  [inline]

Write a sequence of values to the buffer.

Block if full if Policy is BlockingPolicy.

Parameters:
d the values to write
Returns:
the number of values written (may be less than d.size())
Deprecated:
by Push(const std::vector<T>& item)

Definition at line 158 of file BufferLockFree.hpp.

template<class T , class ReadPolicy = NonBlockingPolicy, class WritePolicy = NonBlockingPolicy>
bool RTT::BufferLockFree< T, ReadPolicy, WritePolicy >::write ( param_t  d  )  [inline]

Write a single value to the buffer.

Parameters:
d the value to write
Returns:
false if the buffer is full.
Deprecated:
by Push( param_t item )

Definition at line 132 of file BufferLockFree.hpp.


The documentation for this class was generated from the following file:
Generated on Thu Dec 23 13:22:39 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3