This DataObject is a Lock-Free implementation, such that reads and writes can happen concurrently without priority inversions. More...
#include <DataObjectLockFree.hpp>
Data Structures | |
struct | DataBuf |
Internal buffer structure. | |
Public Types | |
typedef T | DataType |
The type of the data. | |
Public Member Functions | |
DataObjectLockFree (const T &initial_value=T(), unsigned int max_threads=2) | |
Construct a DataObjectLockFree by name. | |
~DataObjectLockFree () | |
virtual DataType | Get () const |
Get a copy of the data. | |
virtual void | Get (DataType &pull) const |
Get a copy of the Data (non allocating). | |
virtual void | Set (const DataType &push) |
Set the data to a certain value (non blocking). | |
virtual void | data_sample (const DataType &sample) |
Data Fields | |
const unsigned int | MAX_THREADS |
The maximum number of threads. |
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.
typedef T DataType |
The type of the data.
Definition at line 79 of file DataObjectLockFree.hpp.
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 128 of file DataObjectLockFree.hpp.
~DataObjectLockFree | ( | ) | [inline] |
Definition at line 139 of file DataObjectLockFree.hpp.
virtual void data_sample | ( | const DataType & | sample | ) | [inline, virtual] |
virtual void 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. |
Definition at line 159 of file DataObjectLockFree.hpp.
virtual DataType 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.
Definition at line 150 of file DataObjectLockFree.hpp.
virtual void 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.
Definition at line 186 of file DataObjectLockFree.hpp.
const unsigned int MAX_THREADS |
The maximum number of threads.
When used in data flow, this is always 2.
Definition at line 86 of file DataObjectLockFree.hpp.