Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Attributes | List of all members
youbot::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>

Classes

struct  DataBuf
 

Public Types

typedef T DataType
 

Public Member Functions

virtual void data_sample (const DataType &sample)
 
 DataObjectLockFree (const T &initial_value=T(), unsigned int max_threads=2)
 
virtual DataType Get () const
 
virtual void Get (DataType &pull) const
 
virtual void Set (const DataType &push)
 
 ~DataObjectLockFree ()
 

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
 
VolPtrType read_ptr
 
VolPtrType write_ptr
 

Detailed Description

template<class T>
class youbot::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 74 of file DataObjectLockFree.hpp.

Member Typedef Documentation

template<class T>
typedef T youbot::DataObjectLockFree< T >::DataType

The type of the data.

Definition at line 79 of file DataObjectLockFree.hpp.

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

Definition at line 111 of file DataObjectLockFree.hpp.

template<class T>
typedef DataBuf youbot::DataObjectLockFree< T >::ValueType
private

Definition at line 110 of file DataObjectLockFree.hpp.

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

Definition at line 109 of file DataObjectLockFree.hpp.

Constructor & Destructor Documentation

template<class T>
youbot::DataObjectLockFree< T >::DataObjectLockFree ( const T &  initial_value = T(),
unsigned int  max_threads = 2 
)
inline

Construct a DataObjectLockFree by name.

Parameters
_nameThe name of this DataObject.
initial_valueThe initial value of this DataObject.

Definition at line 128 of file DataObjectLockFree.hpp.

template<class T>
youbot::DataObjectLockFree< T >::~DataObjectLockFree ( )
inline

Definition at line 139 of file DataObjectLockFree.hpp.

Member Function Documentation

template<class T>
virtual void youbot::DataObjectLockFree< T >::data_sample ( const DataType sample)
inlinevirtual

Definition at line 213 of file DataObjectLockFree.hpp.

template<class T>
virtual DataType youbot::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(DataType&) for the non-allocating version.

Returns
A copy of the data.

Definition at line 150 of file DataObjectLockFree.hpp.

template<class T>
virtual void youbot::DataObjectLockFree< T >::Get ( DataType pull) 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.

Definition at line 159 of file DataObjectLockFree.hpp.

template<class T>
virtual void youbot::DataObjectLockFree< T >::Set ( const DataType push)
inlinevirtual

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

Parameters
pushThe 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.

Definition at line 186 of file DataObjectLockFree.hpp.

Member Data Documentation

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

Conversion of number of threads to size of buffer.

Definition at line 91 of file DataObjectLockFree.hpp.

template<class T>
DataBuf* youbot::DataObjectLockFree< T >::data
private

A 3 element Data buffer

Definition at line 119 of file DataObjectLockFree.hpp.

template<class T>
const unsigned int youbot::DataObjectLockFree< T >::MAX_THREADS

The maximum number of threads.

When used in data flow, this is always 2.

Definition at line 86 of file DataObjectLockFree.hpp.

template<class T>
VolPtrType youbot::DataObjectLockFree< T >::read_ptr
private

Definition at line 113 of file DataObjectLockFree.hpp.

template<class T>
VolPtrType youbot::DataObjectLockFree< T >::write_ptr
private

Definition at line 114 of file DataObjectLockFree.hpp.


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


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Jun 10 2019 15:46:27