Orocos Real-Time Toolkit  2.9.0
Public Types | Public Member Functions | Public 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 <rtt/base/DataObjectLockFree.hpp>

Inheritance diagram for RTT::base::DataObjectLockFree< T >:
RTT::base::DataObjectInterface< T > RTT::base::DataObjectBase RTT::base::DataObject< T >

Public Types

typedef DataObjectInterface< T >::value_t value_t
 
typedef DataObjectInterface< T >::reference_t reference_t
 
typedef DataObjectInterface< T >::param_t param_t
 
typedef DataObjectBase::Options Options
 
typedef boost::shared_ptr< DataObjectInterface< T > > shared_ptr
 Used for shared_ptr management. More...
 

Public Member Functions

 DataObjectLockFree (const Options &options=Options())
 Construct an uninitialized DataObjectLockFree. More...
 
 DataObjectLockFree (param_t initial_value, const Options &options=Options())
 Construct a DataObjectLockFree. More...
 
 ~DataObjectLockFree ()
 
virtual value_t Get () const
 Get a copy of the data. More...
 
virtual FlowStatus Get (reference_t pull, bool copy_old_data, bool copy_sample) const
 Get a copy of the Data (non allocating). More...
 
virtual FlowStatus Get (reference_t pull, bool copy_old_data=true) const
 Get a copy of the Data (non allocating). More...
 
virtual bool Set (param_t push)
 Set the data to a certain value (non blocking). More...
 
virtual bool data_sample (param_t sample, bool reset=true)
 Provides a data sample to initialize this data object. More...
 
virtual value_t data_sample () const
 Reads back a data sample. More...
 
virtual void clear ()
 Clears any data stored by this data object, so that any subsequent Get() without a new Set() will return NoData. More...
 

Public Attributes

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

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.

template<class T >
typedef DataObjectInterface<T>::param_t RTT::base::DataObjectLockFree< T >::param_t

Definition at line 86 of file DataObjectLockFree.hpp.

Definition at line 85 of file DataObjectLockFree.hpp.

template<class T>
typedef boost::shared_ptr<DataObjectInterface<T> > RTT::base::DataObjectInterface< T >::shared_ptr
inherited

Used for shared_ptr management.

Definition at line 68 of file DataObjectInterface.hpp.

template<class T >
typedef DataObjectInterface<T>::value_t RTT::base::DataObjectLockFree< T >::value_t

Definition at line 84 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.

References RTT::base::DataObjectLockFree< T >::data_sample().

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.

References RTT::os::CAS(), RTT::NoData, oro_atomic_dec(), and oro_atomic_inc().

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.

References RTT::NoData.

template<class T >
virtual value_t RTT::base::DataObjectLockFree< T >::data_sample ( ) const
inlinevirtual
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.

Referenced by RTT::base::DataObjectLockFree< T >::data_sample(), and RTT::base::DataObjectLockFree< T >::Get().

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.

References RTT::os::CAS(), RTT::NewData, RTT::NoData, RTT::OldData, oro_atomic_dec(), and oro_atomic_inc().

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.

References RTT::base::DataObjectLockFree< T >::Get().

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.

References RTT::base::DataObjectLockFree< T >::data_sample(), RTT::Error, RTT::internal::DataSourceTypeInfo< T >::getType(), RTT::NewData, oro_atomic_dec(), oro_atomic_inc_and_test(), and oro_atomic_read().

Member Data Documentation

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.


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