Skip to content

iox::concurrent::SoFi🔗

Thread safe producer and consumer queue with a safe overflowing behavior. SoFi is designed in a FIFO Manner but prevents data loss when pushing into a full SoFi. When SoFi is full and a Sender tries to push, the data at the current read position will be returned. SoFi is a Thread safe without using locks. When the buffer is filled, new data is written starting at the beginning of the buffer and overwriting the old.The SoFi is especially designed to provide fixed capacity storage. When its capacity is exhausted, newly inserted elements will cause elements either at the beginning to be overwritten.The SoFi only allocates memory when created , capacity can be is adjusted explicitly. More...

#include <sofi.hpp>

Public Functions🔗

Name
SoFi()
default constructor which constructs an empty sofi
bool push(const ValueType & valueOut, ValueType & f_paramOut_r)
pushs an element into sofi. if sofi is full the oldest data will be returned and the pushed element is stored in its place instead.
bool pop(ValueType & valueOut)
pop the oldest element
template \<typename Verificator_T >
bool
popIf(ValueType & valueOut, const Verificator_T & verificator)
conditional pop call to provide an alternative for a peek and pop approach. If the verificator returns true the peeked element is returned.
bool empty() const
returns true if sofi is empty, otherwise false
bool setCapacity(const uint64_t newSize)
resizes sofi
uint64_t capacity() const
returns the capacity of sofi
uint64_t size() const
returns the current size of sofi

Detailed Description🔗

template <class ValueType ,
uint64_t CapacityValue>
class iox::concurrent::SoFi;

Thread safe producer and consumer queue with a safe overflowing behavior. SoFi is designed in a FIFO Manner but prevents data loss when pushing into a full SoFi. When SoFi is full and a Sender tries to push, the data at the current read position will be returned. SoFi is a Thread safe without using locks. When the buffer is filled, new data is written starting at the beginning of the buffer and overwriting the old.The SoFi is especially designed to provide fixed capacity storage. When its capacity is exhausted, newly inserted elements will cause elements either at the beginning to be overwritten.The SoFi only allocates memory when created , capacity can be is adjusted explicitly.

Parameters:

  • ValueType DataType to be stored, must be trivially copyable
  • CapacityValue Capacity of the SoFi

Public Functions Documentation🔗

function SoFi🔗

SoFi()

default constructor which constructs an empty sofi

function push🔗

bool push(
    const ValueType & valueOut,
    ValueType & f_paramOut_r
)

pushs an element into sofi. if sofi is full the oldest data will be returned and the pushed element is stored in its place instead.

Parameters:

  • valueOut value which should be stored
  • f_paramOut_r if sofi is overflowing the value of the overridden value is stored here

Return: return true if push was sucessfull else false.

 (initial situation, SOFI is FULL)
     Start|-----A-------|
                        |-----B-------|
                                      |-----C-------|
                                                    |-----D-------|


 (calling push with data ’E’)
     Start|-----E-------|
                        |-----A-------|
                                      |-----B-------|
                                                    |-----C-------|
                                     (’D’ is returned as value_out)

###################################################################

 (if SOFI is not FULL , calling push() add new data)
     Start|-------------|
                        |-------------|  ( Initial SOFI )
  (push() Called two times)

                                      |-------------|
                                      (New Data)
                                                     |-------------|
                                                      (New Data)

function pop🔗

bool pop(
    ValueType & valueOut
)

pop the oldest element

Parameters:

  • valueOut storage of the pop'ed value

Return: false if sofi is empty, otherwise true

function popIf🔗

template <typename Verificator_T >
inline bool popIf(
    ValueType & valueOut,
    const Verificator_T & verificator
)

conditional pop call to provide an alternative for a peek and pop approach. If the verificator returns true the peeked element is returned.

Parameters:

  • valueOut storage of the pop'ed value
  • verificator callable of type bool(const ValueType& peekValue) which takes the value which would be pop'ed as argument and returns true if it should be pop'ed, otherwise false
int limit = 7128;
mysofi.popIf(value, [=](const ValueType & peek)
    {
        return peek < limit; // pop only when peek is smaller than limit
    }
); // pop's a value only if it is smaller than 9012

Return: false if sofi is empty or when verificator returns false, otherwise true

first we need to peak valueOut if it is fitting the condition and then we have to verify if valueOut is not am invalid object, this could be the case if the read position has changed

function empty🔗

bool empty() const

returns true if sofi is empty, otherwise false

Note: the use of this function is limited in the concurrency case. if you call this and in another thread pop is called the result can be out of date as soon as you require it

Todoread before write since the writer increments the aba counter!!!

Todowrite doc with example!!!

function setCapacity🔗

bool setCapacity(
    const uint64_t newSize
)

resizes sofi

Parameters:

  • newSize valid values are 0 < newSize < CapacityValue

Precondition: it is important that no pop or push calls occur during this call

function capacity🔗

uint64_t capacity() const

returns the capacity of sofi

function size🔗

uint64_t size() const

returns the current size of sofi


Updated on 26 April 2021 at 15:31:01 CEST