Public Types | Public Member Functions | Public Attributes | Private Types | Private Attributes | List of all members
RTT::base::BufferLockFree< T > Class Template Reference

#include <BufferLockFree.hpp>

Inheritance diagram for RTT::base::BufferLockFree< T >:
Inheritance graph
[legend]

Public Types

typedef BufferBase::Options Options
 
typedef BufferInterface< T >::param_t param_t
 
typedef BufferInterface< T >::reference_t reference_t
 
typedef BufferInterface< T >::size_type size_type
 
typedef T value_t
 
- Public Types inherited from RTT::base::BufferInterface< T >
typedef boost::call_traits< T >::param_type param_t
 
typedef boost::call_traits< T >::reference reference_t
 
typedef boost::shared_ptr< BufferInterface< T > > shared_ptr
 
typedef BufferBase::size_type size_type
 
typedef T value_t
 
- Public Types inherited from RTT::base::BufferBase
typedef boost::shared_ptr< BufferBaseshared_ptr
 
typedef int size_type
 

Public Member Functions

 BufferLockFree (unsigned int bufsize, const Options &options=Options())
 
 BufferLockFree (unsigned int bufsize, param_t initial_value, const Options &options=Options())
 
size_type capacity () const
 
void clear ()
 
virtual bool data_sample (param_t sample, bool reset=true)
 
virtual value_t data_sample () const
 
virtual size_type dropped () const
 
bool empty () const
 
bool full () const
 
FlowStatus Pop (reference_t item)
 
size_type Pop (std::vector< value_t > &items)
 
value_tPopWithoutRelease ()
 
bool Push (param_t item)
 
size_type Push (const std::vector< value_t > &items)
 
void Release (value_t *item)
 
size_type size () const
 
 ~BufferLockFree ()
 
- Public Member Functions inherited from RTT::base::BufferInterface< T >
virtual ~BufferInterface ()
 
- Public Member Functions inherited from RTT::base::BufferBase
virtual ~BufferBase ()
 

Public Attributes

const unsigned int MAX_THREADS
 The maximum number of threads. More...
 

Private Types

typedef value_t Item
 

Private Attributes

internal::AtomicQueue< Item * > *const bufs
 
RTT::os::AtomicInt droppedSamples
 
bool initialized
 
const bool mcircular
 
internal::TsPool< Item > *const mpool
 

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 this buffer, unless the multiple_readers flag in the base::BufferBase::Options struct is set. 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 70 of file BufferLockFree.hpp.

Member Typedef Documentation

template<class T>
typedef value_t RTT::base::BufferLockFree< T >::Item
private

Definition at line 86 of file BufferLockFree.hpp.

template<class T>
typedef BufferBase::Options RTT::base::BufferLockFree< T >::Options

Definition at line 74 of file BufferLockFree.hpp.

template<class T>
typedef BufferInterface<T>::param_t RTT::base::BufferLockFree< T >::param_t

Definition at line 76 of file BufferLockFree.hpp.

Definition at line 75 of file BufferLockFree.hpp.

template<class T>
typedef BufferInterface<T>::size_type RTT::base::BufferLockFree< T >::size_type

Definition at line 77 of file BufferLockFree.hpp.

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

Definition at line 78 of file BufferLockFree.hpp.

Constructor & Destructor Documentation

template<class T>
RTT::base::BufferLockFree< T >::BufferLockFree ( unsigned int  bufsize,
const Options options = Options() 
)
inline

Create an uninitialized lock-free buffer which can store bufsize elements.

Parameters
bufsizethe capacity of the buffer. '

Definition at line 100 of file BufferLockFree.hpp.

template<class T>
RTT::base::BufferLockFree< T >::BufferLockFree ( unsigned int  bufsize,
param_t  initial_value,
const Options options = Options() 
)
inline

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

Parameters
bufsizethe capacity of the buffer.
initial_valueA data sample with which each preallocated data element is initialized.

Definition at line 116 of file BufferLockFree.hpp.

template<class T>
RTT::base::BufferLockFree< T >::~BufferLockFree ( )
inline

Definition at line 128 of file BufferLockFree.hpp.

Member Function Documentation

template<class T>
size_type RTT::base::BufferLockFree< T >::capacity ( ) const
inlinevirtual

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 160 of file BufferLockFree.hpp.

template<class T>
void RTT::base::BufferLockFree< T >::clear ( )
inlinevirtual

Clears all contents of this buffer.

Implements RTT::base::BufferBase.

Definition at line 180 of file BufferLockFree.hpp.

template<class T>
virtual bool RTT::base::BufferLockFree< T >::data_sample ( param_t  sample,
bool  reset = true 
)
inlinevirtual

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

Parameters
samplethe data sample
resetenforce reinitialization even if this operation clears all data.
Returns
true if the buffer was successfully (re)initialized.
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 136 of file BufferLockFree.hpp.

template<class T>
virtual value_t RTT::base::BufferLockFree< T >::data_sample ( ) const
inlinevirtual

Reads back a data sample.

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

Definition at line 148 of file BufferLockFree.hpp.

template<class T>
virtual size_type RTT::base::BufferLockFree< T >::dropped ( ) const
inlinevirtual

Returns the number of dropped samples, because the buffer was full

Implements RTT::base::BufferBase.

Definition at line 187 of file BufferLockFree.hpp.

template<class T>
bool RTT::base::BufferLockFree< T >::empty ( ) const
inlinevirtual

Check if this buffer is empty.

Returns
true if size() == 0

Implements RTT::base::BufferBase.

Definition at line 170 of file BufferLockFree.hpp.

template<class T>
bool RTT::base::BufferLockFree< T >::full ( ) const
inlinevirtual

Check if this buffer is full.

Returns
true if size() == capacity()

Implements RTT::base::BufferBase.

Definition at line 175 of file BufferLockFree.hpp.

template<class T>
FlowStatus RTT::base::BufferLockFree< T >::Pop ( reference_t  item)
inlinevirtual

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 261 of file BufferLockFree.hpp.

template<class T>
size_type RTT::base::BufferLockFree< T >::Pop ( std::vector< value_t > &  items)
inlinevirtual

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 272 of file BufferLockFree.hpp.

template<class T>
value_t* RTT::base::BufferLockFree< T >::PopWithoutRelease ( )
inlinevirtual

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 284 of file BufferLockFree.hpp.

template<class T>
bool RTT::base::BufferLockFree< T >::Push ( param_t  item)
inlinevirtual

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 192 of file BufferLockFree.hpp.

template<class T>
size_type RTT::base::BufferLockFree< T >::Push ( const std::vector< value_t > &  items)
inlinevirtual

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 244 of file BufferLockFree.hpp.

template<class T>
void RTT::base::BufferLockFree< T >::Release ( value_t item)
inlinevirtual

Releases the pointer

Parameters
itempointer aquired using PopWithoutRelease()

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

Definition at line 292 of file BufferLockFree.hpp.

template<class T>
size_type RTT::base::BufferLockFree< T >::size ( ) const
inlinevirtual

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

Returns
number of items.

Implements RTT::base::BufferBase.

Definition at line 165 of file BufferLockFree.hpp.

Member Data Documentation

template<class T>
internal::AtomicQueue<Item*>* const RTT::base::BufferLockFree< T >::bufs
private

Definition at line 90 of file BufferLockFree.hpp.

template<class T>
RTT::os::AtomicInt RTT::base::BufferLockFree< T >::droppedSamples
private

Definition at line 93 of file BufferLockFree.hpp.

template<class T>
bool RTT::base::BufferLockFree< T >::initialized
private

Definition at line 88 of file BufferLockFree.hpp.

template<class T>
const unsigned int RTT::base::BufferLockFree< T >::MAX_THREADS

The maximum number of threads.

Definition at line 83 of file BufferLockFree.hpp.

template<class T>
const bool RTT::base::BufferLockFree< T >::mcircular
private

Definition at line 87 of file BufferLockFree.hpp.

template<class T>
internal::TsPool<Item>* const RTT::base::BufferLockFree< T >::mpool
private

Definition at line 91 of file BufferLockFree.hpp.


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


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:42