Orocos Real-Time Toolkit
2.9.0
|
This DataObject is a Lock-Free implementation, such that reads and writes can happen concurrently without priority inversions. More...
#include <rtt/base/DataObjectLockFree.hpp>
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... | |
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.
typedef DataObjectBase::Options RTT::base::DataObjectLockFree< T >::Options |
Definition at line 88 of file DataObjectLockFree.hpp.
typedef DataObjectInterface<T>::param_t RTT::base::DataObjectLockFree< T >::param_t |
Definition at line 86 of file DataObjectLockFree.hpp.
typedef DataObjectInterface<T>::reference_t RTT::base::DataObjectLockFree< T >::reference_t |
Definition at line 85 of file DataObjectLockFree.hpp.
|
inherited |
Used for shared_ptr management.
Definition at line 68 of file DataObjectInterface.hpp.
typedef DataObjectInterface<T>::value_t RTT::base::DataObjectLockFree< T >::value_t |
Definition at line 84 of file DataObjectLockFree.hpp.
|
inline |
Construct an uninitialized DataObjectLockFree.
max_threads | The maximum number of threads accessing this DataObject. |
Definition at line 141 of file DataObjectLockFree.hpp.
|
inline |
Construct a DataObjectLockFree.
initial_value | The initial value of this DataObject. |
max_threads | The maximum number of threads accessing this DataObject. |
Definition at line 158 of file DataObjectLockFree.hpp.
References RTT::base::DataObjectLockFree< T >::data_sample().
|
inline |
Definition at line 170 of file DataObjectLockFree.hpp.
|
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().
|
inlinevirtual |
Provides a data sample to initialize this data object.
As such enough storage space can be allocated before the actual writing begins.
sample | the data sample |
reset | enforce reinitialization even if this operation clears the stored data. |
Implements RTT::base::DataObjectInterface< T >.
Definition at line 310 of file DataObjectLockFree.hpp.
References RTT::NoData.
|
inlinevirtual |
Reads back a data sample.
Implements RTT::base::DataObjectInterface< T >.
Definition at line 329 of file DataObjectLockFree.hpp.
References RTT::base::DataObjectLockFree< T >::Get().
Referenced by RTT::base::DataObjectLockFree< T >::DataObjectLockFree(), and RTT::base::DataObjectLockFree< T >::Set().
|
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.
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().
|
inlinevirtual |
Get a copy of the Data (non allocating).
If pull has reserved enough memory to store the copy, no memory will be allocated.
pull | A copy of the data. |
copy_old_data | If true, also copy the data if the data object has not been updated since the last call. |
copy_sample | If 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().
|
inlinevirtual |
Get a copy of the Data (non allocating).
If pull has reserved enough memory to store the copy, no memory will be allocated.
pull | A copy of the data. |
copy_old_data | If 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().
|
inlinevirtual |
Set the data to a certain value (non blocking).
push | The 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().
const unsigned int RTT::base::DataObjectLockFree< T >::MAX_THREADS |
The maximum number of threads.
Definition at line 93 of file DataObjectLockFree.hpp.