Orocos Real-Time Toolkit
2.9.0
|
A Lock-free buffer implementation to read and write data of type T in a FIFO way. More...
#include <rtt/base/BufferLockFree.hpp>
Public Types | |
typedef BufferBase::Options | Options |
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 Options &options=Options()) | |
Create an uninitialized lock-free buffer which can store bufsize elements. More... | |
BufferLockFree (unsigned int bufsize, param_t initial_value, const Options &options=Options()) | |
Create a lock-free buffer which can store bufsize elements. More... | |
~BufferLockFree () | |
virtual bool | data_sample (param_t sample, bool reset=true) |
Initializes this buffer with a data sample, such that for dynamical allocated types T, the buffer can reserve place to hold these elements. More... | |
virtual value_t | data_sample () const |
Reads back a data sample. More... | |
size_type | capacity () const |
Returns the maximum number of items that can be stored in the buffer. More... | |
size_type | size () const |
Returns the actual number of items that are stored in the buffer. More... | |
bool | empty () const |
Check if this buffer is empty. More... | |
bool | full () const |
Check if this buffer is full. More... | |
void | clear () |
Clears all contents of this buffer. More... | |
virtual size_type | dropped () const |
Returns the number of dropped samples, because the buffer was full. More... | |
bool | Push (param_t item) |
Write a single value to the buffer. More... | |
size_type | Push (const std::vector< value_t > &items) |
Write a sequence of values to the buffer. More... | |
FlowStatus | Pop (reference_t item) |
Read the oldest value from the buffer. More... | |
size_type | Pop (std::vector< value_t > &items) |
Read the whole buffer. More... | |
value_t * | PopWithoutRelease () |
Returns a pointer to the first element in the buffer. More... | |
void | Release (value_t *item) |
Releases the pointer. More... | |
Public Attributes | |
const unsigned int | MAX_THREADS |
The maximum number of threads. More... | |
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.
T | The 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.
typedef BufferBase::Options RTT::base::BufferLockFree< T >::Options |
Definition at line 74 of file BufferLockFree.hpp.
typedef BufferInterface<T>::param_t RTT::base::BufferLockFree< T >::param_t |
Definition at line 76 of file BufferLockFree.hpp.
typedef BufferInterface<T>::reference_t RTT::base::BufferLockFree< T >::reference_t |
Definition at line 75 of file BufferLockFree.hpp.
|
inherited |
Definition at line 63 of file BufferInterface.hpp.
typedef BufferInterface<T>::size_type RTT::base::BufferLockFree< T >::size_type |
Definition at line 77 of file BufferLockFree.hpp.
typedef T RTT::base::BufferLockFree< T >::value_t |
Definition at line 78 of file BufferLockFree.hpp.
|
inline |
Create an uninitialized lock-free buffer which can store bufsize elements.
bufsize | the capacity of the buffer. ' |
Definition at line 100 of file BufferLockFree.hpp.
|
inline |
Create a lock-free buffer which can store bufsize elements.
bufsize | the capacity of the buffer. |
initial_value | A data sample with which each preallocated data element is initialized. |
Definition at line 116 of file BufferLockFree.hpp.
References RTT::base::BufferLockFree< T >::data_sample().
|
inline |
Definition at line 128 of file BufferLockFree.hpp.
References RTT::base::BufferLockFree< T >::clear().
|
inlinevirtual |
Returns the maximum number of items that can be stored in the buffer.
Implements RTT::base::BufferBase.
Definition at line 160 of file BufferLockFree.hpp.
References RTT::internal::AtomicQueue< T >::capacity().
Referenced by RTT::base::BufferLockFree< T >::Push().
|
inlinevirtual |
Clears all contents of this buffer.
Implements RTT::base::BufferBase.
Definition at line 180 of file BufferLockFree.hpp.
References RTT::internal::TsPool< T >::deallocate(), and RTT::internal::AtomicQueue< T >::dequeue().
Referenced by RTT::base::BufferLockFree< T >::~BufferLockFree().
|
inlinevirtual |
Initializes this buffer with a data sample, such that for dynamical allocated types T, the buffer can reserve place to hold these elements.
sample | the data sample |
reset | enforce reinitialization even if this operation clears all data. |
Implements RTT::base::BufferInterface< T >.
Definition at line 136 of file BufferLockFree.hpp.
References RTT::internal::TsPool< T >::data_sample().
|
inlinevirtual |
Reads back a data sample.
Implements RTT::base::BufferInterface< T >.
Definition at line 148 of file BufferLockFree.hpp.
References RTT::internal::TsPool< T >::allocate(), and RTT::internal::TsPool< T >::deallocate().
Referenced by RTT::base::BufferLockFree< T >::BufferLockFree().
|
inlinevirtual |
Returns the number of dropped samples, because the buffer was full.
Implements RTT::base::BufferBase.
Definition at line 187 of file BufferLockFree.hpp.
References RTT::os::AtomicInt::read().
|
inlinevirtual |
Check if this buffer is empty.
Implements RTT::base::BufferBase.
Definition at line 170 of file BufferLockFree.hpp.
References RTT::internal::AtomicQueue< T >::isEmpty().
|
inlinevirtual |
Check if this buffer is full.
Implements RTT::base::BufferBase.
Definition at line 175 of file BufferLockFree.hpp.
References RTT::internal::AtomicQueue< T >::isFull().
|
inlinevirtual |
Read the oldest value from the buffer.
item | is to be set with a value from the buffer. |
Implements RTT::base::BufferInterface< T >.
Definition at line 261 of file BufferLockFree.hpp.
References RTT::internal::TsPool< T >::deallocate(), RTT::internal::AtomicQueue< T >::dequeue(), RTT::NewData, and RTT::NoData.
|
inlinevirtual |
Read the whole buffer.
items | is to be filled with all values in the buffer, with items.begin() the oldest value. |
Implements RTT::base::BufferInterface< T >.
Definition at line 272 of file BufferLockFree.hpp.
References RTT::internal::TsPool< T >::deallocate(), and RTT::internal::AtomicQueue< T >::dequeue().
|
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.
Implements RTT::base::BufferInterface< T >.
Definition at line 284 of file BufferLockFree.hpp.
References RTT::internal::AtomicQueue< T >::dequeue().
|
inlinevirtual |
Write a single value to the buffer.
item | the value to write |
Implements RTT::base::BufferInterface< T >.
Definition at line 192 of file BufferLockFree.hpp.
References RTT::internal::TsPool< T >::allocate(), RTT::base::BufferLockFree< T >::capacity(), RTT::internal::TsPool< T >::deallocate(), RTT::internal::AtomicQueue< T >::dequeue(), RTT::internal::AtomicQueue< T >::enqueue(), RTT::os::AtomicInt::inc(), and RTT::internal::AtomicQueue< T >::size().
Referenced by RTT::base::BufferLockFree< T >::Push().
|
inlinevirtual |
Write a sequence of values to the buffer.
items | the values to write |
Implements RTT::base::BufferInterface< T >.
Definition at line 244 of file BufferLockFree.hpp.
References RTT::os::AtomicInt::add(), and RTT::base::BufferLockFree< T >::Push().
|
inlinevirtual |
Releases the pointer.
item | pointer aquired using PopWithoutRelease() |
Implements RTT::base::BufferInterface< T >.
Definition at line 292 of file BufferLockFree.hpp.
References RTT::internal::TsPool< T >::deallocate().
|
inlinevirtual |
Returns the actual number of items that are stored in the buffer.
Implements RTT::base::BufferBase.
Definition at line 165 of file BufferLockFree.hpp.
References RTT::internal::AtomicQueue< T >::size().
const unsigned int RTT::base::BufferLockFree< T >::MAX_THREADS |
The maximum number of threads.
Definition at line 83 of file BufferLockFree.hpp.