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

This DataObject is a Lock-Free implementation, such that reads and writes can happen concurrently without priority inversions. More...

#include <DataObjectLockFree.hpp>

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

Classes

struct  DataBuf
 

Public Types

typedef DataObjectBase::Options Options
 
typedef DataObjectInterface< T >::param_t param_t
 
typedef DataObjectInterface< T >::reference_t reference_t
 
typedef DataObjectInterface< T >::value_t value_t
 
- Public Types inherited from RTT::base::DataObjectInterface< T >
typedef boost::call_traits< T >::param_type param_t
 
typedef boost::call_traits< T >::reference reference_t
 
typedef boost::shared_ptr< DataObjectInterface< T > > shared_ptr
 
typedef T value_t
 

Public Member Functions

virtual void clear ()
 
virtual bool data_sample (param_t sample, bool reset=true)
 
virtual value_t data_sample () const
 
 DataObjectLockFree (const Options &options=Options())
 
 DataObjectLockFree (param_t initial_value, const Options &options=Options())
 
virtual value_t Get () const
 
virtual FlowStatus Get (reference_t pull, bool copy_old_data, bool copy_sample) const
 
virtual FlowStatus Get (reference_t pull, bool copy_old_data=true) const
 
virtual bool Set (param_t push)
 
 ~DataObjectLockFree ()
 
- Public Member Functions inherited from RTT::base::DataObjectInterface< T >
 DataObjectInterface ()
 
virtual ~DataObjectInterface ()
 
- Public Member Functions inherited from RTT::base::DataObjectBase
virtual ~DataObjectBase ()
 

Public Attributes

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

Private Types

typedef DataBufPtrType
 
typedef DataBuf ValueType
 
typedef DataBuf *volatile VolPtrType
 

Private Attributes

const unsigned int BUF_LEN
 
DataBufdata
 
bool initialized
 
VolPtrType read_ptr
 
VolPtrType write_ptr
 

Detailed Description

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

This DataObject is a Lock-Free implementation, such that reads and writes can happen concurrently without priority inversions.

When there are more writes than reads, the last write will be returned. The internal buffer can get full if too many concurrent reads are taking to long. In that case, each new read will read the element the previous read returned.

* The following Truth table applies when a Low Priority thread is
* preempted by a High Priority thread :
*
*   L\H | Set | Get |
*   Set | Ok  | Ok  |
*   Get | Ok  | Ok  |
*
* legend : L : Low Priority thread
*          H : High Priority thread
*          Blk: Blocks High Priority thread (bad!)
*          internal::NA : Not allowed !
* 

Further, multiple reads may occur before, during and after a write operation simultaneously. The buffer needs readers+2*writers elements to be guaranteed non blocking.

Definition at line 80 of file DataObjectLockFree.hpp.

Member Typedef Documentation

Definition at line 88 of file DataObjectLockFree.hpp.

Definition at line 86 of file DataObjectLockFree.hpp.

template<class T>
typedef DataBuf* RTT::base::DataObjectLockFree< T >::PtrType
private

Definition at line 123 of file DataObjectLockFree.hpp.

Definition at line 85 of file DataObjectLockFree.hpp.

Definition at line 84 of file DataObjectLockFree.hpp.

template<class T>
typedef DataBuf RTT::base::DataObjectLockFree< T >::ValueType
private

Definition at line 122 of file DataObjectLockFree.hpp.

template<class T>
typedef DataBuf* volatile RTT::base::DataObjectLockFree< T >::VolPtrType
private

Definition at line 121 of file DataObjectLockFree.hpp.

Constructor & Destructor Documentation

template<class T>
RTT::base::DataObjectLockFree< T >::DataObjectLockFree ( const Options options = Options())
inline

Construct an uninitialized DataObjectLockFree.

Parameters
max_threadsThe maximum number of threads accessing this DataObject.

Definition at line 141 of file DataObjectLockFree.hpp.

template<class T>
RTT::base::DataObjectLockFree< T >::DataObjectLockFree ( param_t  initial_value,
const Options options = Options() 
)
inline

Construct a DataObjectLockFree.

Parameters
initial_valueThe initial value of this DataObject.
max_threadsThe maximum number of threads accessing this DataObject.
Note
You have to specify the maximum number of threads explicitly

Definition at line 158 of file DataObjectLockFree.hpp.

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

Definition at line 170 of file DataObjectLockFree.hpp.

Member Function Documentation

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

Clears any data stored by this data object, so that any subsequent Get() without a new Set() will return NoData.

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

Definition at line 337 of file DataObjectLockFree.hpp.

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

Provides a data sample to initialize this data object. As such enough storage space can be allocated before the actual writing begins.

Parameters
samplethe data sample
resetenforce reinitialization even if this operation clears the stored data.
Returns
true if the data object was successfully (re)initialized.

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

Definition at line 310 of file DataObjectLockFree.hpp.

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

Reads back a data sample.

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

Definition at line 329 of file DataObjectLockFree.hpp.

template<class T>
virtual value_t RTT::base::DataObjectLockFree< T >::Get ( ) const
inlinevirtual

Get a copy of the data. This method will allocate memory twice if data is not a value type. Use Get(reference_t) for the non-allocating version.

Returns
A copy of the data.

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

Definition at line 181 of file DataObjectLockFree.hpp.

template<class T>
virtual FlowStatus RTT::base::DataObjectLockFree< T >::Get ( reference_t  pull,
bool  copy_old_data,
bool  copy_sample 
) const
inlinevirtual

Get a copy of the Data (non allocating). If pull has reserved enough memory to store the copy, no memory will be allocated.

Parameters
pullA copy of the data.
copy_old_dataIf true, also copy the data if the data object has not been updated since the last call.
copy_sampleIf true, copy the data unconditionally.

Definition at line 197 of file DataObjectLockFree.hpp.

template<class T>
virtual FlowStatus RTT::base::DataObjectLockFree< T >::Get ( reference_t  pull,
bool  copy_old_data = true 
) const
inlinevirtual

Get a copy of the Data (non allocating). If pull has reserved enough memory to store the copy, no memory will be allocated.

Parameters
pullA copy of the data.
copy_old_dataIf true, also copy the data if the data object has not been updated since the last call.

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

Definition at line 245 of file DataObjectLockFree.hpp.

template<class T>
virtual bool RTT::base::DataObjectLockFree< T >::Set ( param_t  push)
inlinevirtual

Set the data to a certain value (non blocking).

Parameters
pushThe data which must be set.

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

Definition at line 255 of file DataObjectLockFree.hpp.

Member Data Documentation

template<class T>
const unsigned int RTT::base::DataObjectLockFree< T >::BUF_LEN
private

Conversion of number of threads to size of buffer.

Definition at line 99 of file DataObjectLockFree.hpp.

template<class T>
DataBuf* RTT::base::DataObjectLockFree< T >::data
private

A 3 element Data buffer

Definition at line 131 of file DataObjectLockFree.hpp.

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

Definition at line 133 of file DataObjectLockFree.hpp.

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

The maximum number of threads.

Definition at line 93 of file DataObjectLockFree.hpp.

template<class T>
VolPtrType RTT::base::DataObjectLockFree< T >::read_ptr
private

Definition at line 125 of file DataObjectLockFree.hpp.

template<class T>
VolPtrType RTT::base::DataObjectLockFree< T >::write_ptr
private

Definition at line 126 of file DataObjectLockFree.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