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 T | DataType |
typedef T | DataType |
Public Member Functions | |
virtual void | data_sample (const DataType &sample) |
virtual void | data_sample (const DataType &sample) |
DataObjectLockFree (const T &initial_value=T(), unsigned int max_threads=2) | |
DataObjectLockFree (const T &initial_value=T(), unsigned int max_threads=2) | |
virtual void | Get (DataType &pull) const |
virtual DataType | Get () const |
virtual void | Get (DataType &pull) const |
virtual DataType | Get () const |
virtual void | Set (const DataType &push) |
virtual void | Set (const DataType &push) |
~DataObjectLockFree () | |
~DataObjectLockFree () | |
Public Attributes | |
const unsigned int | MAX_THREADS |
The maximum number of threads. | |
Private Types | |
typedef DataBuf * | PtrType |
typedef DataBuf * | PtrType |
typedef DataBuf | ValueType |
typedef DataBuf | ValueType |
typedef DataBuf *volatile | VolPtrType |
typedef DataBuf *volatile | VolPtrType |
Private Attributes | |
const unsigned int | BUF_LEN |
DataBuf * | data |
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 77 of file install/include/rtt/base/DataObjectLockFree.hpp.
typedef T RTT::base::DataObjectLockFree< T >::DataType |
The type of the data.
Reimplemented from RTT::base::DataObjectInterface< T >.
Reimplemented in RTT::base::DataObject< T >, and RTT::base::DataObject< T >.
Definition at line 84 of file rtt/base/DataObjectLockFree.hpp.
typedef T RTT::base::DataObjectLockFree< T >::DataType |
The type of the data.
Reimplemented from RTT::base::DataObjectInterface< T >.
Reimplemented in RTT::base::DataObject< T >, and RTT::base::DataObject< T >.
Definition at line 84 of file install/include/rtt/base/DataObjectLockFree.hpp.
typedef DataBuf* RTT::base::DataObjectLockFree< T >::PtrType [private] |
Definition at line 116 of file rtt/base/DataObjectLockFree.hpp.
typedef DataBuf* RTT::base::DataObjectLockFree< T >::PtrType [private] |
Definition at line 116 of file install/include/rtt/base/DataObjectLockFree.hpp.
typedef DataBuf RTT::base::DataObjectLockFree< T >::ValueType [private] |
Definition at line 115 of file rtt/base/DataObjectLockFree.hpp.
typedef DataBuf RTT::base::DataObjectLockFree< T >::ValueType [private] |
Definition at line 115 of file install/include/rtt/base/DataObjectLockFree.hpp.
typedef DataBuf* volatile RTT::base::DataObjectLockFree< T >::VolPtrType [private] |
Definition at line 114 of file rtt/base/DataObjectLockFree.hpp.
typedef DataBuf* volatile RTT::base::DataObjectLockFree< T >::VolPtrType [private] |
Definition at line 114 of file install/include/rtt/base/DataObjectLockFree.hpp.
RTT::base::DataObjectLockFree< T >::DataObjectLockFree | ( | const T & | initial_value = T() , |
|
unsigned int | max_threads = 2 | |||
) | [inline] |
Construct a DataObjectLockFree by name.
_name | The name of this DataObject. | |
initial_value | The initial value of this DataObject. |
Definition at line 133 of file install/include/rtt/base/DataObjectLockFree.hpp.
RTT::base::DataObjectLockFree< T >::~DataObjectLockFree | ( | ) | [inline] |
Definition at line 144 of file install/include/rtt/base/DataObjectLockFree.hpp.
RTT::base::DataObjectLockFree< T >::DataObjectLockFree | ( | const T & | initial_value = T() , |
|
unsigned int | max_threads = 2 | |||
) | [inline] |
Construct a DataObjectLockFree by name.
_name | The name of this DataObject. | |
initial_value | The initial value of this DataObject. |
Definition at line 133 of file rtt/base/DataObjectLockFree.hpp.
RTT::base::DataObjectLockFree< T >::~DataObjectLockFree | ( | ) | [inline] |
Definition at line 144 of file rtt/base/DataObjectLockFree.hpp.
virtual void RTT::base::DataObjectLockFree< T >::data_sample | ( | const DataType & | sample | ) | [inline, virtual] |
Provides a data sample to initialize this data object. As such enough storage space can be allocated before the actual writing begins.
sample |
Implements RTT::base::DataObjectInterface< T >.
Definition at line 218 of file rtt/base/DataObjectLockFree.hpp.
virtual void RTT::base::DataObjectLockFree< T >::data_sample | ( | const DataType & | sample | ) | [inline, virtual] |
Provides a data sample to initialize this data object. As such enough storage space can be allocated before the actual writing begins.
sample |
Implements RTT::base::DataObjectInterface< T >.
Definition at line 218 of file install/include/rtt/base/DataObjectLockFree.hpp.
virtual void RTT::base::DataObjectLockFree< T >::Get | ( | DataType & | pull | ) | const [inline, virtual] |
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. |
Implements RTT::base::DataObjectInterface< T >.
Definition at line 164 of file rtt/base/DataObjectLockFree.hpp.
virtual DataType RTT::base::DataObjectLockFree< T >::Get | ( | ) | const [inline, virtual] |
Get a copy of the data. This method will allocate memory twice if data is not a value type. Use Get(DataType&) for the non-allocating version.
Implements RTT::base::DataObjectInterface< T >.
Definition at line 155 of file rtt/base/DataObjectLockFree.hpp.
virtual void RTT::base::DataObjectLockFree< T >::Get | ( | DataType & | pull | ) | const [inline, virtual] |
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. |
Implements RTT::base::DataObjectInterface< T >.
Definition at line 164 of file install/include/rtt/base/DataObjectLockFree.hpp.
virtual DataType RTT::base::DataObjectLockFree< T >::Get | ( | ) | const [inline, virtual] |
Get a copy of the data. This method will allocate memory twice if data is not a value type. Use Get(DataType&) for the non-allocating version.
Implements RTT::base::DataObjectInterface< T >.
Definition at line 155 of file install/include/rtt/base/DataObjectLockFree.hpp.
virtual void RTT::base::DataObjectLockFree< T >::Set | ( | const DataType & | push | ) | [inline, virtual] |
Set the data to a certain value (non blocking).
push | The data which must be set. |
This method can not be called concurrently (only one producer). With a minimum of 3 buffers, if the write_ptr+1 field is not occupied, it will remain so because the read_ptr is at write_ptr-1 (and can not increment the counter on write_ptr+1). Hence, no locking is needed.
Implements RTT::base::DataObjectInterface< T >.
Definition at line 191 of file rtt/base/DataObjectLockFree.hpp.
virtual void RTT::base::DataObjectLockFree< T >::Set | ( | const DataType & | push | ) | [inline, virtual] |
Set the data to a certain value (non blocking).
push | The data which must be set. |
This method can not be called concurrently (only one producer). With a minimum of 3 buffers, if the write_ptr+1 field is not occupied, it will remain so because the read_ptr is at write_ptr-1 (and can not increment the counter on write_ptr+1). Hence, no locking is needed.
Implements RTT::base::DataObjectInterface< T >.
Definition at line 191 of file install/include/rtt/base/DataObjectLockFree.hpp.
const unsigned int RTT::base::DataObjectLockFree< T >::BUF_LEN [private] |
Conversion of number of threads to size of buffer.
Definition at line 96 of file install/include/rtt/base/DataObjectLockFree.hpp.
DataBuf * RTT::base::DataObjectLockFree< T >::data [private] |
A 3 element Data buffer
Definition at line 124 of file install/include/rtt/base/DataObjectLockFree.hpp.
const unsigned int RTT::base::DataObjectLockFree< T >::MAX_THREADS |
The maximum number of threads.
When used in data flow, this is always 2.
Definition at line 91 of file install/include/rtt/base/DataObjectLockFree.hpp.
VolPtrType RTT::base::DataObjectLockFree< T >::read_ptr [private] |
Definition at line 118 of file install/include/rtt/base/DataObjectLockFree.hpp.
VolPtrType RTT::base::DataObjectLockFree< T >::write_ptr [private] |
Definition at line 119 of file install/include/rtt/base/DataObjectLockFree.hpp.