This DataObject is a Lock-Free implementation, such that reads and writes can happen concurrently without priority inversions. More...
#include <DataObjectLockFree.hpp>
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 DataBuf * | PtrType |
typedef DataBuf | ValueType |
typedef DataBuf *volatile | VolPtrType |
Private Attributes | |
const unsigned int | BUF_LEN |
DataBuf * | data |
bool | initialized |
VolPtrType | read_ptr |
VolPtrType | write_ptr |
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.
|
private |
Definition at line 123 of file DataObjectLockFree.hpp.
typedef DataObjectInterface<T>::reference_t RTT::base::DataObjectLockFree< T >::reference_t |
Definition at line 85 of file DataObjectLockFree.hpp.
typedef DataObjectInterface<T>::value_t RTT::base::DataObjectLockFree< T >::value_t |
Definition at line 84 of file DataObjectLockFree.hpp.
|
private |
Definition at line 122 of file DataObjectLockFree.hpp.
|
private |
Definition at line 121 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.
|
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.
|
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.
|
inlinevirtual |
Reads back a data sample.
Implements RTT::base::DataObjectInterface< T >.
Definition at line 329 of file DataObjectLockFree.hpp.
|
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.
|
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.
|
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.
|
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.
|
private |
Conversion of number of threads to size of buffer.
Definition at line 99 of file DataObjectLockFree.hpp.
|
private |
A 3 element Data buffer
Definition at line 131 of file DataObjectLockFree.hpp.
|
private |
Definition at line 133 of file DataObjectLockFree.hpp.
const unsigned int RTT::base::DataObjectLockFree< T >::MAX_THREADS |
The maximum number of threads.
Definition at line 93 of file DataObjectLockFree.hpp.
|
private |
Definition at line 125 of file DataObjectLockFree.hpp.
|
private |
Definition at line 126 of file DataObjectLockFree.hpp.